Using the SwipeDismissBehavior
suggest changeThe 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);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents