RecycleView1

嵌套滑动--》RecyclerView

// --》 dispatchNestedPreScroll --> scrollByInternal --> dispatchNestedScroll --> 边缘效果

                         --》scrollByInternal

                             --》scrollStep(x, y, mReusableIntPair);

                                   --> mLayout.scrollHorizontallyBy

                                   --> mLayout.scrollVerticallyBy

                                        --> scrollBy

                                             --> fill

                                                --> layoutChunk

                                                  -->  View view = layoutState.next(recycler);

                                                    --》recycler.getViewForPosition

                                                       --》tryGetViewHolderForPositionByDeadline // 主要的复用代码

                                    --> measureChildWithMargins(view, 0, 0); // 测量,padding margin inset(分割线的空间)

四级复用:

1. getChangedScrapViewForPosition --》mChangedScrap (position、StableId)

2. getScrapOrHiddenOrCachedHolderForPosition --》mAttachedScrap、mCachedViews(ForPosition)

3. getScrapOrCachedViewForId --》mAttachedScrap、mCachedViews(StableId)

4. mViewCacheExtension.getViewForPositionAndType --》 自定义复用,缓存需要自己实现

5. getRecycledViewPool().getRecycledView

6. mAdapter.createViewHolder --> onCreateViewHolder --> 创建ViewHolder 对象

7. tryBindViewHolderByDeadline --> onBindViewHolder --> 处理数据

缓存--> onLayoutChildren --> detachAndScrapAttachedViews(recycler); --> recycler.scrapView(view);

fill

--》recycleViewsFromStart

--》recycleChildren

--》removeAndRecycleViewAt

--》recycler.recycleView

--》recycleViewHolderInternal // 关键代码,(cacheView、pool)

  --》mCachedViews

      --》 如果满了--》recycleCachedViewAt(0);

      --》 新的Item肯定是放在CacheView 中的

--》CacheView 把老的移除集合,放入pool 中

--》Pool

      --》addViewHolderToRecycledViewPool(viewHolder, true); // 添加到Pool中

        --》getRecycledViewPool().putRecycledView(holder);

            --》viewType = scrap.getItemViewType();

            --》scrap.resetInternal();

            --》scrapHeap.add(scrap);

ArrayList mCachedViews --》 DEFAULT_CACHE_SIZE =2 --> setViewCacheSize

ArrayList scrapHeap --》 DEFAULT_MAX_SCRAP =5 --> setMaxRecycledViewsViewHolder

从缓存池中 复用  ViewHolder:需要调用 onBindViewHOdler

从 CacheView复用:不用调用 onBindViewHOdler

从缓存中没有拿到 ViewHolder: onCreate onBind

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 分析RV的缓存机制,先思考一下什么时候用到缓存机制,从源码的哪个角度去看,缓存肯定是在滑动的时候去做的,所以我们从...
    leap_阅读 624评论 0 2
  • 一、RecyclerView的四级缓存 (1)mChangedScrap、mAttachedScrap: 用于屏幕...
    zzq_nene阅读 2,063评论 1 2
  • 首先看一下为何说RecycleView(主要有适配器模式,观察者模式adapter通知更新UI)中的adapter...
    唯爱_0834阅读 749评论 0 7
  • 这篇文章分三个部分,简单跟大家讲一下 RecyclerView 的常用方法与奇葩用法;工作原理与ListView比...
    LucasAdam阅读 4,436评论 0 27
  • RecyclerView RecyclerView,顾名思义,这个View代表的就是一个可循环使用的视图集合控件,...
    杰奎琳子阅读 725评论 0 13