ViewPager 的 Android Viewholder
您好,我正在使用 ViewPager,但我现在想保留状态,而不是重新生成单元格。
我注意到 viewpager 与 listviews 的自定义适配器非常相似,它们的功能类似,listview 在单元格不再出现在屏幕上后重新生成单元格中的数据,viewpager 也是如此。
有没有办法做一个viewholder,某种在最初加载后保留每个视图状态的对象,以便viewpager单元加载得更快。 (每个单元格都有一些处理和渲染,但我会自己测试内存的限制)
Hello I am using a ViewPager but I would now like to retain states, instead of having cells regenerated.
I notice viewpager is very similar to a custom adapter for listviews, and they function similarly where listview regenerate data in cells after they are no longer on screen, viewpager is the same way.
Is there a way to do a viewholder, some kind of object that retains the state of each view, after it is loaded initially, so that the viewpager cells load quicker. (there is some processing and rendering for each cell, but I'll test the limits of the memory myself)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 FragmentPagerAdapter,它将所有已主动创建的 Fragment 对象保留在内存中:
Use FragmentPagerAdapter, which keeps all Fragment objects that have been created actively in memory:
膨胀布局后,创建布局的 hashMap。如果您已经有相应页面的布局,只需替换 hashMap 中的布局,否则膨胀新布局并将其存储在 hashMap 中。我不能保证你是否可以恢复状态。但它会减少用户每次在页面之间切换时的膨胀时间。
Make a hashMap of the layouts after you inflate them. If you already have a layout for corresponding page just replace the layout from hashMap , otherwise inflate the new layout and store it in hashMap. I cannot guarantee if you can restore states. But it will reduce your inflating time every time the user switches between pages.