Android Recyclerview预加载视图

Android Recyclerview预加载视图,android,android-recyclerview,preload,Android,Android Recyclerview,Preload,我想知道,当用户滚动快一点时,如何避免recyclerview中的视图出现白色的“闪烁”。 当然,可以通过在可见屏幕外预加载更多视图来避免闪烁 我还找不到任何方法可以做到这一点,虽然这一定是一个相当常见的任务 我在博客上尝试了以下代码: public class PreCachingLayoutManager extends LinearLayoutManager { private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 600;

我想知道,当用户滚动快一点时,如何避免recyclerview中的视图出现白色的“闪烁”。
当然,可以通过在可见屏幕外预加载更多视图来避免闪烁

我还找不到任何方法可以做到这一点,虽然这一定是一个相当常见的任务

我在博客上尝试了以下代码:

public class PreCachingLayoutManager extends LinearLayoutManager {
    private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 600;
    private int extraLayoutSpace = -1;
    private Context context;

    public PreCachingLayoutManager(Context context) {
        super(context);
        this.context = context;
    }

    public PreCachingLayoutManager(Context context, int extraLayoutSpace) {
        super(context);
        this.context = context;
        this.extraLayoutSpace = extraLayoutSpace;
    }

    public PreCachingLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
        this.context = context;
    }

    public void setExtraLayoutSpace(int extraLayoutSpace) {
        this.extraLayoutSpace = extraLayoutSpace;
    }

    @Override
    protected int getExtraLayoutSpace(RecyclerView.State state) {
        if (extraLayoutSpace > 0) {
            return extraLayoutSpace;
        }
        return DEFAULT_EXTRA_LAYOUT_SPACE;
    }
}
然后,我使用setLayoutManager()
这是“自定义”,但我只想在构造函数中设置LayoutManager,这就是我重写RecyclerView的原因

不幸的是,这并没有产生任何效果

RecyclerView已经是一个非常有效的API,通常,如果您有框架下降,您可以优化项目布局,使其更轻,并确保在回收视图时释放资源。实际上没有必要预加载任何内容

下面是一篇博客文章,给出了一些如何做这些事情的想法

他们在这篇文章中没有提到,但是如果你的物品有图片,请确保这些图片不是太大

主要的一点是尽可能快地绘制视图,因为在滚动时,所有内容都会不断地重新绘制