当 Fragment 隐藏时,为什么 Fragment 中的 SurfaceView 仍然可见? [英] Why is a SurfaceView in a Fragment still visible when the Fragment is hidden?

查看:41
本文介绍了当 Fragment 隐藏时,为什么 Fragment 中的 SurfaceView 仍然可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个一般性问题:我有一个带有 SurfaceView 的 Fragment.当我通过 FragmentManager 隐藏 Fragment 时,SurfaceView 仍然可见.

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.

我找到了一种解决方法,即在 Fragment 隐藏/可见时将 View 设置为 INVISIBLE/GONE/VISIBLE - 但我想知道:为什么 SurfaceView 仍然显示?是不是因为SurfaceView 基本上是一个打孔",也就是说,它不在Fragment 的Layout-Hierarchy 中,因此在Layout 隐藏时无法隐藏?

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?

Fragment 的隐藏过程是做什么的?它是否只是将创建的视图设置为消失?

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

推荐答案

SurfaceView 创建一个完全独立的图形层,由系统合成.洞"包含在视图层次结构中,因此布局正确.当涉及到 SurfaceView 时,很多事情都不能正常工作.

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.

TextureView 相比之下,实际上是视图本身的一部分,并且会适当地采取行动.缺点是有一个额外的步骤,将像素从屏幕外缓冲区复制到视图中.这是由 GPU 完成的,因此速度非常快,但是如果您尝试以 60fps 的速度对大部分屏幕进行动画处理或在播放全长电影时尽量减少电池消耗,那么 SurfaceView 可能是更好的选择.

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.

如果使用 TextureView 是一种选择,那么这样做可能会让您的生活更简单一些.

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

这篇关于当 Fragment 隐藏时,为什么 Fragment 中的 SurfaceView 仍然可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆