GL Surface and Visibility: Gone
Asked Answered
A

1

8

So I have a GLSurfaceView in my app being rendered by a GLSurfaceView.Renderer and using JPCt as library.

The surface is in an invisible RelativeLayout (visibility: gone). When I change the visibility to "visible" then back to "gone", the layout shows and hides as expected, but the GLSurfaceView don't, it just shows and won't hide, even though I can click on items that are now "behind" it.

It seems like some graphical buffer issue, but I didn't find a way to get this to work... any ideas? Thanks!

Alcaeus answered 26/8, 2012 at 20:35 Comment(0)
M
14

SurfaceView (and GLSurfaceView by extension) are interesting beasts in Android. Citation from Android javadoc:

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it

Android has a built-in window compositor (window has a bit different meaning here). Your status bar is a window, your activity has one window. But if your activity contains a surface view, another window is created, just to hold the surface, and android compositor draws the window with your views over the surface window. So the SurfaceView is really only a transparent area. When you hid it, the area is not drawn, does not react to touches, but the surface window is still present, android is not clever enough to hide the window.

I would recommend two solutions

  • Make your surface translucent. You can then render empty surface when you need to hide the view( Android, Transparent sub-GLSurfaceView in layout? )
  • Remove the view from view hierarchy altogether
  • Another a bit hacky way is to subclass GLSurfaceView and call onDetachedFromWindow() when visibility changes to GONE. I have not tested this and it might not work.
Mansized answered 26/8, 2012 at 21:3 Comment(2)
I used solution 1 by rendering transparent color. Many thanksSheatfish
Another possible answer is to render it off screen entirely, by doing something along the lines of setX(view.getMeasuredWidth()), and then setX(0) when you want it back on screen. This is useful if you don't want a translucent background and/or you need the view to measure correctly (which you won't get when it's not attached).Cavalla

© 2022 - 2024 — McMap. All rights reserved.