android - Sinch 本地摄像头视图始终保持在顶部
问题描述
我有这个显示视频的视图
<FrameLayout
android:id="@+id/remoteViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/remote_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/local_view"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="bottom|right" />
</FrameLayout>
单击后local_view
,我需要从两者中删除视图RelativeLayout
并在不同位置再次添加它们。我正在使用标志来了解当前加载的视图。
private String loadedView = "1";
binding.contentSinchIncomingCall.localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (videoController == null) {
videoController = mSinchServiceInterface.getVideoController();
}
if (loadedView.equals("1")) {
loadedView = "2";
((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());
binding.contentSinchIncomingCall.remoteView.addView(videoController.getLocalView());
binding.contentSinchIncomingCall.localView.addView(videoController.getRemoteView());
binding.contentSinchIncomingCall.localView.requestLayout();
binding.contentSinchIncomingCall.localView.invalidate();
binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);
} else {
loadedView = "1";
((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());
binding.contentSinchIncomingCall.remoteView.addView(videoController.getRemoteView());
binding.contentSinchIncomingCall.localView.addView(videoController.getLocalView());
binding.contentSinchIncomingCall.localView.requestLayout();
binding.contentSinchIncomingCall.localView.invalidate();
binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);
}
}
});
但改变位置后,remote_view
重叠local_view
。我正在使用 BringChildToFront 方法将其带到local_view
前面,但仍然无法正常工作。请帮我解决这个问题。
解决方案
由于远程和本地视频都是覆盖表面,因此标准的视图层次操作 APIbringChildToFront
将不起作用。将覆盖视图视为视频视图上方所有层中的“切割”矩形孔,这使得覆盖始终“在顶部”。显然,当两个“始终位于顶部”的叠加视图重叠时,就会发生冲突。这已在Sinch Android SDK 3.13.0中得到解决。请使用 VideoController 的setLocalVideoZOrder
:
设置是否应在删除视频视图(默认行为)之上渲染本地视频(来自相机的预览),反之亦然,以防视图重叠。* @param onTopOfRemoteView 如果设置为 false 将删除在预览顶部渲染的视频。
void setLocalVideoZOrder(boolean onTopOfRemoteView);
推荐阅读
- android - 如何在 android 的适配器视图中添加底部导航栏?
- javascript - Webpack字符串插值在html文件中不起作用
- python - 将具有列表值的 Python 字典列表转换为具有单个值的字典的平面列表
- node.js - Nodjs 语法错误意外令牌 JSON 在位置 0
- node.js - CORS 问题不一致 - 2 个示例(VueJS 和 NodeJs)
- database - 如何在 DynamoDB 中高效地存储和检索聚合数据?
- python - 在python中,如何获取特定子PID的父PID?
- javascript - 有没有办法映射所有 HTML 元素和子元素?
- ruby-on-rails - Rails Job 随机丢失对模块的引用
- powerbi - powerbi 不从 ssas 更新