Android GLSurfaceView transparent background without setZOrderonTop

假如想象 提交于 2019-11-29 06:09:38

This worked for me:

final GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.glView);

glView.setZOrderOnTop(true);
glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glView.getHolder().setFormat(PixelFormat.RGBA_8888);
glView.setRenderer(new MyRenderer());
glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

Found here: http://andrewhague.wordpress.com/2011/05/24/how-to-set-a-transparent-glsurfaceview/

I would like to accomplish the same thing with a view on top of a GLSurfaceView and I have not found a solution without limitations. First, glView.setZOrderOnTop(true) gives the correct transparent background but the view is alway on top no matter what the sequence of ordering views. Second, without ZOrderOnTop the view hierarchy is maintained but the GLSurface background is black or the color that is set with glClearColor(red, green, blue, alpha) in the renderer. Unfortunately, the alpha argument has no effect when using this method unless

android:windowIsTranslucent="true"

and the problem with this is that you may not want to punch a hole into the OS view. There should be a way to accomplish this easily for a more animated UI using openGL. I have searched this site and others without finding a solution.

I'm working the same problem. I found that you have to make the calls for

setZOrderOnTop(true);
getHolder().setFormat(PixelFormat.RGBA_8888);

before the call to

setRenderer(...);

Good luck!

user2610335

I was also facing the same issue that nothing view was showing when I was using GLSurfaceView.

After getting the reference of GLSurfaceView do like this

glSurface=findViewById(R.id.gl_surfaceview)

//this is the import line only

glSurface.setZOrderOnTop(false)

now my all view are visible on top of GLSurfaceView

Thanks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!