Behavoiur没有关于完成投掷的事件

时间:2017-07-16 07:26:00

标签: android android-coordinatorlayout

我的自定义行为可以捕获所有滚动事件。但是,如果发生了抛弃,它不会得到滚动事件(因为它正在甩动),开始抛出事件,并且不会结束投掷事件。结果我不能做相应的行为。

出了什么问题?如何捕捉关于投掷的事件被停止了?

    class MyCustomBehaviour(val context: Context, val attr: AttributeSet)
        : CoordinatorLayout.Behavior<MyFloatingButton>(context, attr) {

        override fun layoutDependsOn(parent: CoordinatorLayout, child: MyFloatingButton, dependency: View): Boolean {
            return when (dependency) {
                is Snackbar.SnackbarLayout -> true
                else -> super.layoutDependsOn(parent, child, dependency)
            }
        }

        override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout,
                                         child: MyFloatingButton,
                                         directTargetChild: View,
                                         target: View,
                                         nestedScrollAxes: Int): Boolean {
            return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
        }

        override fun onNestedScroll(coordinatorLayout: CoordinatorLayout,
                                    child: MyFloatingButton,
                                    target: View,
                                    dxConsumed: Int, dyConsumed: Int,
                                    dxUnconsumed: Int, dyUnconsumed: Int) {
            // got it when scroll happens
        }


        override fun onNestedFling(coordinatorLayout: CoordinatorLayout,
                                   child: MyFloatingButton,
                                   target: View,
                                   velocityX: Float, velocityY: Float, consumed: Boolean): Boolean {
            // got it when fling started
            return true;
        }

        override fun onStopNestedScroll(coordinatorLayout: CoordinatorLayout, child: MyFloatingButton, target: View) {
            // got it when scroll (not fling!) finished
            // but there is no event when fling finished. why??
        }
    }

0 个答案:

没有答案