【发布时间】:2014-07-31 23:03:48
【问题描述】:
我在片段中有一个GLSurfaceView,这是我的主要片段。当我从带有 GLSurfaceView 的片段过渡到没有 GLSurfaceView 的另一个片段时,GLSurfaceView 在过渡开始前稍微向上移动。
我尝试设置GLSurfaceView.setZOrderOnTop(true),但它不起作用,而且在这种情况下实际上弊大于利,因为我的广告和导航抽屉变得模糊。
我尝试隐藏托管 GLSurfaceView 的 Fragment,仍然没有效果。
我尝试暂停托管 GLSurfaceView 的片段,因此同时暂停 GLSurfaceView 没有效果。
当 GLSurfaceView 向上移动时,屏幕是黑色的,而 GLSurfaceView 应该是。屏幕上的黑色区域似乎特定于片段转换,因为如果我删除转换并简单地用片段事务进行替换,那么 glsurfaceview 运动就消失了。这不是一个解决方案,因为我希望我的应用程序中的转换从一个片段到另一个片段。
最后,我意识到 ondestroyview 正在使用 GLSurfaceView 在片段上调用,因此在动画过渡到下一个片段之前破坏了视图,我认为这可能是问题所在。
这是一些代码...
使用 glsurfaceview 添加片段
//clear all fragments from the back stack if there are any
getSupportFragmentManager()
.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
//start a new deploy fragment
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, new DeployFragment(), "Main Fragment")
.commit();
用偏好列表片段替换 glsurfaceview 片段
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left,
R.anim.enter_from_left, R.anim.exit_to_right)
.replace(R.id.container, new SettingsFragment(), "Settings Fragment")
.addToBackStack(null)
.commit();
当从 DeployFragment(glsurfaceview 片段)过渡到 SettingsFragment(常规列表片段)时,GLSurfaceView 会向上移动一点,可能与堆叠在一起的 2 个操作栏的高度差不多。向上移动的 glsurfaceview 还会在屏幕上显示 GLSurfaceView 应该是的黑色区域,但事实并非如此。
任何想法如何解决这个问题?
问题视频
选择一个选项后,您会看到 GLSurfaceView 向上移动,露出黑色空间
【问题讨论】:
-
请记住,SurfaceView 表面是独立于所有 View UI 元素合成的。此外,它们的位置由窗口管理器管理,而不是在应用程序内。有关完整故事,请参阅source.android.com/devices/graphics/architecture.html
-
您在使用支持片段时找到解决方案了吗?我现在也面临同样的问题
标签: android android-fragments android-support-library glsurfaceview