SurfaceView
is the sole culprit (of course, this also applies to GLSurfaceView
, RSSurfaceView
and VideoView
, all of which inherits from SurfaceView
). It exposes lots of weird behaviours when dealing with other views on top of it. Playing with View.setVisibility()
is one of those issues. Clearly, SurfaceView
has not been designed to be used with other views (even though the official doc says it ought to be) but as a standalone view for videos, games or OpenGL stuffs.
For the visibility issue, I've found that using View.GONE
instead of View.INVISIBLE
resolve it. If you don't want to use View.GONE
, try changing the focus for example (and back to the one that had focus before), or changing other states. The goal is to wake up the underlying UI system somehow.
In short: when something weird happens with your views and you have a SurfaceView
(or subclass) somewhere, try replacing it with something else so you don't lose hours searching what you're doing wrong when you're doing it right (and no false beliefs). This way, you know SurfaceView
is to blame and you can hack around it with beautiful comments to piss on it without qualms.
As answered here.
EDIT:
Get a copy of LayoutParams
for later use:
RelativeLayout.LayoutParams rllp = (RelativeLayout.LayoutParams) vid
.getLayoutParams();
Remove VideoView completely
((ViewGroup) vid.getParent()).removeView(vid);
Recreate VideoView
with same LayoutParams
when needed.
vid = new VideoView(someContext);
vid.setLayoutParams(rllp);