如果RecyclerView的项目滚动了50%,如何检测CoordinatorLayout.Behaviour内部?

时间:2017-10-01 20:23:48

标签: android android-recyclerview android-coordinatorlayout

我有以下布局:

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"          
        app:layout_behavior="com.github.an.CustomBehaviour">

        //Other views

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

CustomBehaviour内部onNestedScroll(...)如果第一个RecyclerView的元素已滚动50%(或部分),我想做一些事情:

public class CustomBehaviour extends CoordinatorLayout.Behavior<AppBarLayout> {

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, final AppBarLayout appbar, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {

        if(first element scrolled partially) {
            do something
        }

    }
}

有可能实现这个目标吗?

0 个答案:

没有答案