ViewPager + SurfaceView =长延时导航时回到活动 [英] ViewPager + SurfaceView = long delay when navigating back to activity
问题描述
基本上什么标题说,
我的应用程序主要由一个 ViewPager
它采用了 FragmentStatePagerAdapter
My application consists primarily of a ViewPager
which uses a FragmentStatePagerAdapter
当我添加了一系列 SurfaceViews发生问题
到FragmentStatePagerAdapter。
只是用于测试目的我没有子类SurfaceViews以任何方式。
当我浏览的,打了几页家,然后返回到活动中,整个设备冻结了两秒钟渲染才作罢。我可以在它需要为它被拉断backstack后恢复时间启动并完成()的应用程序几次。我知道,应用程序正在运行,因为一些AsyncTasks已经由第一screendraw最后出现的时间基本完成。我知道这些AsyncTasks不会导致问题,因为我已删除他们没有影响。
The problem occurs when I add a series of SurfaceViews
to the FragmentStatePagerAdapter.
Just for testing purposes I did not subclass the SurfaceViews in any way.
When I navigate a few pages in, hit "home," and then return to the activity, the entire device freezes for a second or two before rendering anything. I can launch and finish() the app several times in the time it takes for it to resume after being pulled off of the backstack. I know that the application is running because several AsyncTasks have nearly finished by the time the first screendraw finally occurs. I know that these AsyncTasks do not cause the problem because I have removed them to no effect.
当我改变SurfaceViews到 浏览
问题完全消失。
When I change the SurfaceViews to Views
the problem vanishes entirely.
当我用我的实际SurfaceViews(这是没有商量余地的我的项目),以及会出现此问题。此问题也发生在多个设备上。
This problem occurs when I use my actual SurfaceViews (which are non-negotiable for my project) as well. This problem also occurs on multiple devices.
在这一点上,我认为故障出正视的ViewPager,但我不知道该怎么办才好,因为我需要一个界面组件。
At this point I think the fault lies squarely on the ViewPager, but I don't know what to do about it because I need that interface component.
任何帮助将是很大的AP preciated!
Any help would be greatly appreciated!
编辑:
要澄清,该SurfaceViews /浏览次数再present其添加到FragmentStatePagerAdapter片段的视图。
To clarify, the SurfaceViews/Views represent the View of the Fragment which was added to the FragmentStatePagerAdapter.
推荐答案
找到任何未来谷歌的解决方案!
Found the solution for any future googlers!
继承人如何我做到了:
在我的片段,我实例化mySurfaceView中的onCreate()
In my fragment I instantiated mySurfaceView in onCreate()
然后我onCreateView()
Then I attached a dummy layout (LinearLayout) to the actual view during onCreateView()
然后在onResume()我与清除的removeAllViews虚拟布局(),然后叫addView(mySurfaceView)
Then in onResume() I cleared the dummy layout with removeAllViews() and then called addView(mySurfaceView)
这似乎让ViewPager快速建立自己的布局,然后在SurfaceView只是突然出现在之前用户实际需要看到什么!
This seems to allow the ViewPager to build its layout quickly and then the SurfaceView is just popped in before the user actually needs to see anything!
这篇关于ViewPager + SurfaceView =长延时导航时回到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!