Using the SwipeDismissBehavior

suggest change

The SwipeDismissBehavior works on any View and implements the functionality of swipe to dismiss in our layouts with 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
LayoutParams coordinatorParams = 
    (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