RecyclerView实现吸顶效果项目实战(四),2021年Android开发爆款推荐

本文深入解析了RecyclerView的布局流程,包括onLayoutChildren方法在不同子类中的实现,以及如何确定布局锚点并进行填充。同时,分析了RecyclerView的触摸事件处理,特别是ACTION_MOVE时如何调用scrollByInternal方法来处理滑动。通过源码阅读,揭示了RecyclerView如何高效地复用View并滚动更新内容。
摘要由CSDN通过智能技术生成

private void dispatchLayoutStep1() {

if (mState.mRunPredictiveAnimations) {

mLayout.onLayoutChildren(mRecycler, mState);

} else {

clearOldPositions();

}

}

dispatchLayoutStep1 方法中调用了 mLayoutonLayoutChildren 方法。上面分析告诉我们,mLayout 就是 LayoutManager,所以我们转到 LayoutManageronLayoutChildren 方法。

public void onLayoutChildren(Recycler recycler, State state) {

Log.e(TAG, "You must override onLayoutChildren(Recycler recycler, State state) ");

}

onLayoutChildren 方法是一个空实现,其具体实现在各个子类中。我们拿 LinearLayoutManager 进行分析,看其中 onLayoutChildren 的实现。

public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {

// layout algorithm:

// 1) by checking children and other variables, find an anchor coordinate and an anchor

// item position.

// 2) fill towards start, stacking from bottom

// 3) fill towards end, stacking from top

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

// 4) scroll to fulfill requirements like stack from bottom.

// create layout state

if (mAnchorInfo.mLayoutFromEnd) {

} else {

// fill towards end

updateLayoutStateToFillEnd(mAnchorInfo);

mLayoutState.mExtra = extraForEnd;

fill(recycler, mLayoutState, state, false);

endOffset = mLayoutState.mOffset;

final int lastElement = mLayoutState.mCurrentPosition;

if (mLayoutState.mAvailable > 0) {

extraForStart += mLayoutState.mAvailable;

}

// fill towards start

updateLayoutStateToFillStart(mAnchorInfo);

mLayoutState.mExtra = extraForStart;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值