ViewPager FragmentStatePagerAdapter在内存中保留三个以上的片段 [英] ViewPager FragmentStatePagerAdapter keep more than three fragments in memory

查看:114
本文介绍了ViewPager FragmentStatePagerAdapter在内存中保留三个以上的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我有某种类型的阅读器,横向显示两页,纵向显示一页。由于某种原因,我阻止了破坏配置更改的活动。这个故事与这里的 ViewPager + FragmentStatePagerAdapter +方向更改几乎相同。尽管问题有点不同-我希望不存储3个而是5个片段。关于渲染时间,Im可以轻松地通过纵向添加+ -1和横向添加+ -2来轻松处理滑动内容,尽管问题是,在横向方向上,它无法渲染正确的下一个/上一个片段。显然,它渲染+1和-1项,因此我想实例化+ 2 / -2项。因此,有一种解决方案可以更改位置以在横向中实例化(虽然我暂时不知道),还是可以在适配器中存储5个项目而不是仅存储3个项目。
有任何适当解决方案的人吗?

The problem is ive got sort of book reader, landscape shows two pages and portrait just one. For some reason I blocked destroying activities on config change. the story is pretty much the same like here ViewPager + FragmentStatePagerAdapter + orientation change. Although the question is bit different - Id wish to store not 3 but 5 fragments. its about rendering time, Im easily handling swipe stuffs with adding +-1 in portrait and +-2 in landscape, though the problem is, in landscape orientation, it wont render proper next / previous fragments. As obviously its rendering +1 and -1 items, I want +2/-2 items to be instantiated instead. So theres either some kind of solution that changes positions to instantiate in landscape (which im not aware of though), or storing 5 items in an adapter instead of just 3. Anyone with any sort of proper solution?

推荐答案

通过将ViewPager的OffscreenPageLimit设置为4,可以在适配器中存储5个项目:

You can store 5 items in the adapter by setting the OffscreenPageLimit of the ViewPager to 4:

viewPager.setOffscreenPageLimit(4);

希望我对您有所帮助。

这篇关于ViewPager FragmentStatePagerAdapter在内存中保留三个以上的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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