ViewPager + SurfaceView = 导航回活动时的长时间延迟

ViewPager + SurfaceView = long delay when navigating back to activity(ViewPager + SurfaceView = 导航回活动时的长时间延迟)
本文介绍了ViewPager + SurfaceView = 导航回活动时的长时间延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上就是标题所说的,

Basically what the title says,

我的应用程序主要由 ViewPager 使用 FragmentStatePagerAdapter

My application consists primarily of a ViewPager which uses a FragmentStatePagerAdapter

当我添加一系列 SurfaceViews 到 FragmentStatePagerAdapter.仅出于测试目的,我没有以任何方式对 SurfaceViews 进行子类化.当我浏览几页,点击主页",然后返回活动时,整个设备会冻结一两秒钟,然后再渲染任何内容.我可以在从后台退出后恢复应用程序的时间内多次启动和完成()应用程序.我知道应用程序正在运行,因为在第一个屏幕绘制最终发生时,几个 AsyncTask 几乎完成了.我知道这些 AsyncTask 不会导致问题,因为我已将它们删除,但没有任何效果.

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 更改为 Views 问题完全消失.

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.

任何帮助将不胜感激!

为了澄清,SurfaceViews/Views 代表被添加到 FragmentStatePagerAdapter 的 Fragment 的 View.

To clarify, the SurfaceViews/Views represent the View of the Fragment which was added to the FragmentStatePagerAdapter.

推荐答案

为任何未来的谷歌员工找到了解决方案!

Found the solution for any future googlers!

我是这样做的:

在我的片段中,我在 onCreate() 中实例化了 mySurfaceView

In my fragment I instantiated mySurfaceView in onCreate()

然后我在 onCreateView() 期间将虚拟布局(LinearLayout)附加到实际视图

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 = 导航回活动时的长时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)