AppbarLayoutBehavior
AppbarLayoutBehavior copied to clipboard
你这个解决方案不就是 杨充 的方案吗,但是还是有问题
和 AppBarLayout 一起协作滚动的 兄弟可嵌套滚动的 view,比如 RecyclerView,在 RecyclerView fling 时,但是此时 AppBarLayout 还没滑出屏幕,此时 再去滚动 由于 shouldBlockNestedScroll 已经 为 true 会阻止 AppBarLayout 滚动,所以出现滚动断层现象!
如何解决
这里有个方案:https://github.com/ckrgithub/CollapsingRefresh
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, @NonNull AppBarLayout child, View target, int dx, int dy, int[] consumed, int type ) {
if (type == TYPE_FLING) {
isFlinging = true;
}
if (!shouldBlockNestedScroll) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
} else if (TYPE_FLING == type) {
if (null == consumed) consumed = new int[2];
consumed[1] = dy;
}
}
加上 else if 这段试试