首页 > 解决方案 > 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前面,但仍然无法正常工作。请帮我解决这个问题。

截图:- 首次加载的视图

点击后

标签: androidviewsinch

解决方案


由于远程和本地视频都是覆盖表面,因此标准的视图层次操作 APIbringChildToFront将不起作用。将覆盖视图视为视频视图上方所有层中的“切割”矩形孔,这使得覆盖始终“在顶部”。显然,当两个“始终位于顶部”的叠加视图重叠时,就会发生冲突。这已在Sinch Android SDK 3.13.0中得到解决。请使用 VideoController 的setLocalVideoZOrder

设置是否应在删除视频视图(默认行为)之上渲染本地视频(来自相机的预览),反之亦然,以防视图重叠。* @param onTopOfRemoteView 如果设置为 false 将删除在预览顶部渲染的视频。

void setLocalVideoZOrder(boolean onTopOfRemoteView);

推荐阅读