美文网首页
CoordinatorLayout

CoordinatorLayout

作者: 两手空空_6214 | 来源:发表于2017-11-21 15:24 被阅读0次

在滑动的时候出现TabLayout还没到顶部的时候RecyclerView就会滑动的情况。

分析原因,RecyclerView快速滑动是在onTouchEvent的ACTION_UP里面调用fling。

fling方法里调dispatchNestedPreFling,如果它返回false,就快速滚动。dispatchNestedPreFling调用CoordinatorLayout的onNestedPreFling方法,返回布尔对象handled。如果handled为true,就表明CoordinatorLayout来处理事件,RecyclerView不处理。

onNestedPreFling遍历child的Behavior的onNestedPreFling方法,并把结果取或,就是说只要有一个返回true,handled就为true。

查看AppBarHeaderBehavior的onNestedPreFling,让滑动距离小于AppBarLayout.getTotalScrollRange的时候返回true,这样在没有滑动到顶部之前RecyclerView就不会处理事件。

相关文章

网友评论

      本文标题:CoordinatorLayout

      本文链接:https://www.haomeiwen.com/subject/jorwvxtx.html