Blenden Sie den FloatingActionButton in Scroll von RecyclerView aus

Möchte ich zum ein - /ausblenden FloatingActionButton auf Blättern von RecyclerView.

XML:

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview_eventlist"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab_createevent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/fab_margin"
                app:layout_anchor="@id/recyclerview_eventlist"
                app:layout_anchorGravity="bottom|right|end"
                app:layout_behavior="com.eventizon.behavior.ScrollAwareFABBehavior"
                android:src="@drawable/ic_edit"
                app:backgroundTint="@color/custom_color_1"
                app:borderWidth="0dp" />
        </android.support.design.widget.CoordinatorLayout>

DrawerLayout ist das übergeordnete layout-dieses layout.

public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {


private static final String TAG = "ScrollAwareFABBehavior";

public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
    super();
    Log.e(TAG,"ScrollAwareFABBehavior");
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout,
        FloatingActionButton child, View target, int dxConsumed,
        int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    //TODO Auto-generated method stub
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
            dxUnconsumed, dyUnconsumed);
    Log.e(TAG,"onNestedScroll called");
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        Log.e(TAG,"child.hide()");
        child.hide();
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
        Log.e(TAG,"child.show()");
        child.show();
    }
}

}

Verwendet das layout Verhalten für FloatingActionButton. Wenn ich sehe logcat nur Konstruktor wird immer aufgerufen. onNestedScroll() nicht aufgerufen, wenn ich durch die Liste scrollen.

InformationsquelleAutor der Frage Pritam Kadam | 2015-10-19

Schreibe einen Kommentar