
I'm creating a floating popup with a surface view into it, in this manner:
LayoutInflater.from(contextWeak.get()).inflate(R.layout.layout_floating_widget, null); int type;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
type = WindowManager.LayoutParams.TYPE_TOAST;
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
type,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
//Specify the view position
params.gravity = Gravity.LEFT | Gravity.CENTER; //Initially view will be added to top-left corner
params.x = 0;
params.y = 0;
//Add the view to the window
mWindowManager = (WindowManager) contextWeak.get().getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView, params);
localVideoView = mFloatingView.findViewById(R.id.local_gl_surface_view);
remoteVideoView = mFloatingView.findViewById(R.id.remote_gl_surface_view);
localVideoView.setZOrderOnTop(true);
remoteVideoView.setZOrderOnTop(true);
And the xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--Root container-->
<RelativeLayout android:id="@+id/root_container" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="UselessParent">
<RelativeLayout android:id="@+id/collapse_view" android:layout_width="wrap_content" android:visibility="visible" android:layout_height="wrap_content" android:orientation="vertical" android:background="#ccc">
<LinearLayout android:id="@+id/video" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<org.webrtc.SurfaceViewRenderer android:id="@+id/remote_gl_surface_view" android:layout_width="150dp" android:layout_height="100dp" />
<org.webrtc.SurfaceViewRenderer android:id="@+id/local_gl_surface_view" android:layout_width="150dp" android:layout_height="100dp" />
</LinearLayout>
<!--Close button-->
<ImageView android:id="@+id/close_btn" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_close" tools:ignore="ContentDescription" android:layout_toEndOf="@id/video"/>
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
On Android 9 it's properly rendered and I can drag it with its content, but on Android 6
I'm seeing the SurfaceView being rendered like out of the layout and I can drag it but it drags the popup without the SurfaceView.
Image showing the issue:
https://imgur.com/a/ai79aI7Video showing the issue:
https://imgur.com/a/ChltcBTI've created the question also on StackOverflow ->
https://stackoverflow.com/questions/53728963/surfaceview-getting-rendered-out-of-layout