Android ViewPager 滞后

Android ViewPager Lag(Android ViewPager 滞后)
本文介绍了Android ViewPager 滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个带有多个页面的视图分页器(使用片段状态分页器),以及一些 png 作为这些页面的背景.我已经按照 Ui 中的显示位图 (http://developer.android.com/training/display-bitmaps/display-bitmap.html) 所以我已经在后台线程中缓存和设置可绘制的图像.但是在切换寻呼机页面时我仍然会遇到一些滞后.在每个片段上,我只对 onCreateView() 方法的视图进行膨胀,所以我不知道是什么导致了这种滞后.我可以做些什么来消除这种滞后/断断续续的影响?

Hello I have a viewpager with several pages(using a fragment state pager), and some pngs as backgrounds to those pages. I already followed the Displaying Bitmaps in the Ui (http://developer.android.com/training/displaying-bitmaps/display-bitmap.html) so I am already caching and setting the image drawable in a background thread. But I still get some lag when swithcing pages of the pager. On Each fragment, I only inflate the view on the onCreateView() method, so I have no Idea what may be causing this lag. What can I do to remove this lag/choppy effect?

推荐答案

我也遇到了类似的问题.

I had similar problem.

我正在显示类似教程的页面.每页都是全屏jpg.

I am showing tutorial-like pages. Each page is a full screen jpg.

一开始,我把图片放在res/drawables文件夹中.浏览器在滑动时非常滞后.

At first, I put the pictures in res/drawablesfolder. The viewpager is very laggy when swiping it.

然后我将这些 jpg 文件移动到 res/drawable-hdpi 文件夹,延迟消失了.

Then I move those jpgs to res/drawable-hdpi folder, the lag is gone.

我认为根据文件夹对图片进行了不同的优化.所以我们不能把所有东西都放在 res/drawable 文件夹中

I think different optimisations are done on the pictures based on folder. So we cannot put everything in res/drawable folder

这篇关于Android ViewPager 滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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)