什么是viewPager.setOffscreenPageLimit(3)的实际效果;? [英] What is the practical effect of viewPager.setOffscreenPageLimit(3);?

查看:565
本文介绍了什么是viewPager.setOffscreenPageLimit(3)的实际效果;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个页面,并且已经设置页数限制为3。

I have three pages and have set Page Limit to 3.

  mViewPager.setOffscreenPageLimit(3);

这样做有什么实际效果?是否提高性能多还是可以导致内存消耗问题?

What is the practical effect of this? Does it improve performance much or can it cause memory consumption issues?

推荐答案

文件:<一href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit%28int%29" rel="nofollow">http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)

设置应该保留到的任一侧的页数   当前页面中处于空闲状态的视图层次。超出此页   限制,由需要的时候适配器重新创建。

Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.

这是作为一个优化。如果你事先知道多少   网页,你需要支持或有延迟加载机制   放置在您的网页,调整这个设置可以有益处   感知分页动画和互动的平滑度。如果你有   少数页(3-4),你可以保持所有活动的一次,   更少的时间将在布局新创建的视图子树的花   用户页面来回。

This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth.

您应该保持此限制较低,特别是如果你的网页有复杂   布局。此设置默认为1。

You should keep this limit low, especially if your pages have complex layouts. This setting defaults to 1.

如果你只使用三个页面,然后你在文档描述的情况是,它应该让你的用户界面更顺畅。当然它的消耗内存,但只要你留在这样的范围内它不应该是一个问题。

If you use only three pages then you're still on the case the documentation describe, and it should allow your UI to be smoother. Of course it's consuming memory but as long as you stay in such a range it shouldn't be a problem.

这篇关于什么是viewPager.setOffscreenPageLimit(3)的实际效果;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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