Reputation: 32233
I have a RelativeLayout containing a custom SurfaceView and other elements that must be drawn over the SurfaceView. I also need the SurfaceView to be transparent. I tried this answer: how to make surfaceview transparent. But with the setZOrderOnTop(true) the other elements over the SurfaceView in the RelativeLayout are shown above the Surface (and partially hidden if the surface have something paint).
How can I solve this problem? thanks
Upvotes: 10
Views: 6939
Reputation: 21
This Solution works for me
glSurfaceView = view;
glSurfaceView.setZOrderMediaOverlay(true);
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
glSurfaceView.setRenderer(renderer);
glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
glSurfaceView.requestRender();
Upvotes: 0
Reputation: 176
Set the holder pixel format to RGBA_8888,
sv.setZOrderOnTop(true); //very much necessary
getHolder().setFormat(PixelFormat.RGBA_8888);
Upvotes: 3
Reputation: 472
I had success with the setZOrderMediaOverlay(true)
instead of setZOrderOnTop(true)
. It allows for both Views below and above the OpenGL SurfaceView.
Here it is in context:
GLSurfaceView glview = (GLSurfaceView)findViewById(R.id.surface);
glview.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glview.getHolder().setFormat(PixelFormat.RGBA_8888);
glview.setZOrderMediaOverlay(true);
glview.setEGLContextClientVersion(2);
Upvotes: 0