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

问题描述

您好我使用的是ViewPager,但现在我想保留,而不必细胞再生的状态。

Hello I am using a ViewPager but I would now like to retain states, instead of having cells regenerated.

我注意到viewpager非常相似的列表视图自定义适配器,以及它们的功能相似,其中的ListView数据再生的细胞中后,他们不再是在屏幕上,viewpager也是同样的道理。

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.

有没有办法做一个viewholder,某些类型的对象,其保持每个视图的状态,加载后开始,这样viewpager细胞加载更快。 (有一些处理和渲染每一个细胞,但我会测试存储自己的极限)

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)

这里是我的viewpager

推荐答案

使用FragmentPagerAdapter,这使已积极创建内存中的所有片段的对象:

Use FragmentPagerAdapter, which keeps all Fragment objects that have been created actively in memory:

/**
 * Implementation of {@link android.support.v4.view.PagerAdapter} that
 * represents each page as a {@link Fragment} that is persistently
 * kept in the fragment manager as long as the user can return to the page.
 */

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

09-02 13:18