zoukankan      html  css  js  c++  java
  • Android:ListView 和RecyclerView区别

    缓存机制

     ListView的两级缓存

    ListView的缓存和复用由它的父类AbsListView中的RecycleBin实现,设了两个缓存数组mActiveViews和mScrapViews。mActiveViews缓存显示在屏幕中的view,mScrapViews按ViewType缓存离屏的view

    class RecycleBin {
        /**
         * The position of the first view stored in mActiveViews.
         */
        private int mFirstActivePosition;
    
        /**
         * Views that were on screen at the start of layout. This array is populated at the start of
         * layout, and at the end of layout all view in mActiveViews are moved to mScrapViews.
         * Views in mActiveViews represent a contiguous range of Views, with position of the first
         * view store in mFirstActivePosition.
         */
        private View[] mActiveViews = new View[0];
    
        /**
         * Unsorted views that can be used by the adapter as a convert view.
         */
        private ArrayList<View>[] mScrapViews;
    }

    RecyclerView的四级缓存

     RecyclerView的缓存和复用由Recycler实现,mAttachedScrap和mCachedViews的缓存方式跟ListView相似。mRecyclerPool是多个RecyclerView的复用池,mViewCacheExtension不直接使用,需要用户再定制,默认不实现。

    public final class Recycler {
        final ArrayList<ViewHolder> mAttachedScrap = new ArrayList<>();
        final ArrayList<ViewHolder> mCachedViews = new ArrayList<ViewHolder>();
        RecycledViewPool mRecyclerPool;
        private ViewCacheExtension mViewCacheExtension;
    }

    缓存内容

    1. ListView缓存View
    2. RecyclerView缓存ViewHolder,抽象可理解为:View + ViewHolder(避免每次createView时调用findViewById)

    总结

    ListView二级缓存

    RecyclerView四级缓存

  • 相关阅读:
    位记录——Windows 7已安装Sublime Text 3、cynwin、SublimeClang
    尺度空间(Scale space)理论
    D3DXMatrixMultiply 函数
    素数推断算法(高效率)
    去除win7 64位系统桌面图标小箭头
    Bag标签之中的一个行代码实行中文分词实例1
    7个最好的免费杀毒软件下载
    利用Excel批量高速发送电子邮件
    Hibernate Criterion
    IOS新手教程(二)-控制流
  • 原文地址:https://www.cnblogs.com/billshen/p/13340947.html
Copyright © 2011-2022 走看看