Why is a SurfaceView in a Fragment still visible when the Fragment is hidden?

落爺英雄遲暮 提交于 2019-12-22 21:13:12

问题


Just a general question: I have a Fragment which has a SurfaceView. When I hide the Fragment by the FragmentManager, the SurfaceView is still visible.

I found a workaround by just setting the View to INVISIBLE/GONE/VISIBLE when the Fragment is hidden/visible - but I'm wondering: Why is the SurfaceView still shown? Is it because the SurfaceView basically is a "punched hole", which means, it's not in the Layout-Hierarchy of the Fragment and therefore can't be hidden when the Layout is hidden?

What is the hiding-procedure doing with the Fragment? Does it simply sets the created view to gone?


回答1:


A SurfaceView creates an entirely separate graphics layer, composited by the system. The "hole" is included in the view hierarchy so the layout comes out right. There's a lot of things that don't quite work right when SurfaceView is involved.

A TextureView, by contrast, is actually part of the View itself, and will act appropriately. The disadvantage is that there's an extra step where pixels are copied from an off-screen buffer into the view. This is done by the GPU, so it's very fast, but if you're trying to animate a large portion of the screen at 60fps or minimize battery drain while playing a full-length movie then SurfaceView may be a better choice.

If using a TextureView is an option, doing so may make your life a bit simpler.



来源:https://stackoverflow.com/questions/21447263/why-is-a-surfaceview-in-a-fragment-still-visible-when-the-fragment-is-hidden

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