如何缓存片段视图 [英] How to cache a fragment view

查看:256
本文介绍了如何缓存片段视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缓存片段视图。我的活动有swipeable选项卡和每个标签调用不同的片段。但是,当我轻扫标签之间的过渡,似乎是因为片段视图的破坏,即在滑动操作期间rebuilded的相当缓慢。有谁知道我怎么能缓存中的每个片段,以prevent这个问题的看法? 我和库支持V4和API的14个工作

I'd like to cache a fragment view. My Activity has swipeable tabs and each tab calls a different fragment. But when i swipe between tabs the transition seems a quite slow because of the destruction of the fragment view, that is rebuilded during the swipe operation. Does anyone know how can i cache the view of each fragment to prevent this issue? I work with library support v4 and api 14

我想实现一个构造函数片段,称为片段的活性容器:我调用构造函数,该片段被创建为活动类的变量,然后,每当一个片段必须显示自身活动类将返回我之前创建的片段的对象,但是这并不能提高我的应用程序很多,因为碎片的看法是反正破坏

I tried to implement a constructor for the fragments, called by the activity container of the fragments: i call the constructor, the fragments are created as variable of the activity class and then, whenever a fragment has to show itself, the activity class returns the fragment object i created before, but this doesn't improve my application a lot because the view of the fragment is destroyed anyway

推荐答案

这是因为内部默认寻呼机加载最多的时候3页(片段): 显示一个,previous和明年,所以如果你有5个片段,而你从第一位置移动到最后会出现这种情况:(其中x是一个加载的片段)

This is because internally by default the pager loads a maximum of 3 pages (fragments) at the time: the one displaying, previous and next so if you have 5 fragments this will happen while you move from first to last: (where x is a loaded fragment)

xx000 - > xxx00 - > 0xxx0 - > 00xxx - > 000xx

xx000 -> xxx00 -> 0xxx0 -> 00xxx -> 000xx

尝试使用

myPager.setOffscreenPageLimit(ITEMS_COUNT-1);

这将告诉寻呼机让所有的人都在内存中,不破坏/每刷卡创建(保持在内存管理仔细看)

This will tell the pager to keep all of them in memory and not destroy/create with every swipe (keep a close look on the memory management)

这篇关于如何缓存片段视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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