如何删除appbar上的弹跳效果? [英] How do I remove the bouncing effect on appbar?

查看:116
本文介绍了如何删除appbar上的弹跳效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Appbar在猛扑时曾经有问题.它滚动不流畅.

请参考以下内容:

但是它在支持库版本26中已得到修复.

compile 'com.android.support:design:26.0.0'

但是,即使猛击并不困难,appbar现在仍可以弹回.

如何删除此行为?

解决方案

这仅在NestedScrollView(或RecyclerView)尚未完成甩动的情况下滚动/抛掷AppBar时发生.

解决方案:扩展AppBar的默认Behavior并阻止对AppBar的调用.在NestedScroll尚未停止时触摸AppBar时,行为的onNestedPreScroll()onNestedScroll().

 @Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, 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);
    }
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
    if (!shouldBlockNestedScroll) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
    }
}

然后在布局上使用它:

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    ...
    app:layout_behavior="com.mypackage.NoBounceBehavior"/>

有关自定义行为的完整代码的

参考可以在以下位置找到: https://gist.github.com/ampatron/9d56ea401094f67196f407f82f14551a

Appbar used to have an issue when flinging. It was not scrolling smoothly.

Please refer to these:

But it has been fixed in support library version 26.

compile 'com.android.support:design:26.0.0'

However, appbar is now bouncing back even if fling is not hard.

How do I remove this behavior?

解决方案

This is only happening when AppBar is scrolled/flung while the NestedScrollView(or RecyclerView) has not yet finish flinging.

Solution: Extend AppBar's default Behavior and block the call for AppBar.Behavior's onNestedPreScroll() and onNestedScroll() when AppBar is touched while NestedScroll hasn't stopped yet.

 @Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, 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);
    }
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
    if (!shouldBlockNestedScroll) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
    }
}

then use it on the layout:

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    ...
    app:layout_behavior="com.mypackage.NoBounceBehavior"/>

Reference for full code of the custom behavior can be found here: https://gist.github.com/ampatron/9d56ea401094f67196f407f82f14551a

这篇关于如何删除appbar上的弹跳效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆