ScrollAwareFABBehavior防止在回收站查看overscroll边缘效应

我正在使用FAB隐藏和显示取决于用户是否向上或向下滚动的自定义行为。 这里是代码:

class ScrollAwareFABBehavior(context: Context, attrs: AttributeSet) : FloatingActionButton.Behavior(context, attrs) { var hidden = false var animatingOut = false var animatingIn = false override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton, directTargetChild: View?, target: View?, nestedScrollAxes: Int): Boolean { // Ensure we react to vertical scrolling return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL } override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton, target: View?, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) { if (dyConsumed > 0 && !hidden && !animatingIn) { // User scrolled down and the FAB is currently visible -> hide the FAB hidden = true val animation = child.animate().scaleY(0F).scaleX(0F).alpha(0F).setDuration(200) animation.setListener(object : Animator.AnimatorListener { override fun onAnimationRepeat(animator: Animator) { } override fun onAnimationEnd(animator: Animator) { animatingOut = false child.visibility = View.INVISIBLE } override fun onAnimationCancel(animator: Animator) { } override fun onAnimationStart(animator: Animator) { animatingOut = true } }) animation.start() } else if (dyConsumed < 0 && hidden && !animatingOut) { // User scrolled up and the FAB is currently not visible -> show the FAB hidden = false val animation = child.animate().scaleY(1F).scaleX(1F).alpha(1F).setDuration(200) animation.setListener(object : Animator.AnimatorListener { override fun onAnimationRepeat(animator: Animator) { } override fun onAnimationEnd(animator: Animator) { animatingIn = false } override fun onAnimationCancel(animator: Animator) { } override fun onAnimationStart(animator: Animator) { animatingIn = true } }) child.visibility = View.VISIBLE animation.start() } } } 

(是的,它在Kotlin,但应该很容易理解)

问题是,它可以防止边缘效应(滚动超过最大值或最小值时)出现在回收站视图中。

任何人都可以解释为什么这样做? 你知道一个修复/解决方法吗? 谢谢!