嵌套滑动--》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