View->startNestedScroll(int axes)
主要作用:初始化mNestedScrollingParent为父ViewGroup(若存在),调用父viewgroup的onStartNestedScroll
View->dispatchNestedScroll(int dxConsumed, int dyConsumed,int dxUnconsumed, int dyUnconsumed, @Nullable @Size(2) int[] offsetInWindow)
调用父viewParent的onNestedScroll onNestedScroll的默认实现是调用this.dispatchNestedScroll继续向viewParent分发
View->dispatchNestedPreScroll(int dx, int dy,@Nullable @Size(2) int[] consumed, @Nullable @Size(2) int[] offsetInWindow)
调用父viewParent的onNestedPreScroll(这里可以提前消耗掉一部分横向或者垂直滑动的值) onNestedPreScroll的默认实现是调用this.dispatchNestedPreScroll继续向viewParent分发
总结
所以要想实现嵌套滚动,覆盖onNestedPreScroll、onNestedScroll是必须的,而且onStartNestedScroll还要返回true。
on**NestedScroll是ViewGroup的方法,dispatch****、****NestedScroll是view的方法
RecyclerView嵌套滑动
主要逻辑是在onTouchEvent
DOWN事件中执行startNestedScroll,但不会验证返回值 MOVE事件首先会执行dispatchNestedPreScroll,让父view预先执行,之后自己再执行scrollStep滑动一段距离,如果此view消耗掉一段距离或者仍有剩余距离再让父View执行onNestedScroll。