Using the SwipeDismissBehavior

suggest change

The SwipeDismissBehavior implements swipe-to-dismiss for a direct child of a CoordinatorLayout.

Just use:

final SwipeDismissBehavior<MyView> swipe = new SwipeDismissBehavior<>();

//Sets the swipe direction for this behavior.
swipe.setSwipeDirection(
    SwipeDismissBehavior.SWIPE_DIRECTION_ANY);

//Set the listener to be used when a dismiss event occurs
swipe.setListener(
    new SwipeDismissBehavior.OnDismissListener() {
    @Override public void onDismiss(View view) {
        //......
    }

    @Override 
    public void onDragStateChanged(int state) {
        //......
    }
});

//Attach the SwipeDismissBehavior to a view
CoordinatorLayout.LayoutParams coordinatorParams =
    (CoordinatorLayout.LayoutParams) mView.getLayoutParams();    
coordinatorParams.setBehavior(swipe);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents