# SwipeDismissBehavior

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/behavior/SwipeDismissBehavior.java)

*** ** * ** ***


```
public class SwipeDismissBehavior<V extends View>
```

<br />

Known direct subclasses [BaseTransientBottomBar.Behavior](https://developer.android.com/reference/com/google/android/material/snackbar/BaseTransientBottomBar.Behavior)

|---|---|
| `https://developer.android.com/reference/com/google/android/material/snackbar/BaseTransientBottomBar.Behavior` | Behavior for `https://developer.android.com/reference/com/google/android/material/snackbar/BaseTransientBottomBar`. |

*** ** * ** ***

An interaction behavior plugin for child views of CoordinatorLayout to provide support for the 'swipe-to-dismiss' gesture.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior.OnDismissListener` Callback interface used to notify the application that the view has been dismissed. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_DRAGGING()` A view is currently being dragged. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_IDLE()` A view is not currently being dragged or animating as a result of a fling/snap. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_SETTLING()` A view is currently settling into place as a result of a fling or predefined non-interactive motion. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_ANY() = 2` Swipe direction which allows swiping in either direction. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_END_TO_START() = 1` Swipe direction that only allows swiping in the direction of end-to-start. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_START_TO_END() = 0` Swipe direction that only allows swiping in the direction of start-to-end. |

| ### Public fields |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior.OnDismissListener` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#listener()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SwipeDismissBehavior()()` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#canSwipeDismissView(View)(View view)` Called when the user's input indicates that they want to swipe the given view. |
| `int` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#getDragState()()` Retrieve the current drag state of this behavior. |
| `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior.OnDismissListener` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#getListener()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#onInterceptTouchEvent(CoordinatorLayout,V,MotionEvent)( CoordinatorLayout parent, V child, MotionEvent event )` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#onLayoutChild(CoordinatorLayout,V,int)(CoordinatorLayout parent, V child, int layoutDirection)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#onTouchEvent(CoordinatorLayout,V,MotionEvent)(CoordinatorLayout parent, V child, MotionEvent event)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setDragDismissDistance(float)(float distance)` Set the threshold for telling if a view has been dragged enough to be dismissed. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setEndAlphaSwipeDistance(float)(float fraction)` The maximum swipe distance for the view's alpha is modified. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setListener(com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener)(https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior.OnDismissListener listener)` Set the listener to be used when a dismiss event occurs. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setSensitivity(float)(float sensitivity)` Set the sensitivity used for detecting the start of a swipe. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setStartAlphaSwipeDistance(float)(float fraction)` The minimum swipe distance before the view's alpha is modified. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#setSwipeDirection(int)(int direction)` Sets the swipe direction for this behavior. |

## Constants

### STATE_DRAGGING

```
public static final int STATE_DRAGGING
```

A view is currently being dragged. The position is currently changing as a result of user input or simulated user input.

### STATE_IDLE

```
public static final int STATE_IDLE
```

A view is not currently being dragged or animating as a result of a fling/snap.

### STATE_SETTLING

```
public static final int STATE_SETTLING
```

A view is currently settling into place as a result of a fling or predefined non-interactive motion.

### SWIPE_DIRECTION_ANY

```
public static final int SWIPE_DIRECTION_ANY = 2
```

Swipe direction which allows swiping in either direction.

### SWIPE_DIRECTION_END_TO_START

```
public static final int SWIPE_DIRECTION_END_TO_START = 1
```

Swipe direction that only allows swiping in the direction of end-to-start. That is right-to-left in LTR or left-to-right in RTL.

### SWIPE_DIRECTION_START_TO_END

```
public static final int SWIPE_DIRECTION_START_TO_END = 0
```

Swipe direction that only allows swiping in the direction of start-to-end. That is left-to-right in LTR, or right-to-left in RTL.

## Public fields

### listener

```
public SwipeDismissBehavior.OnDismissListener listener
```

## Public constructors

### SwipeDismissBehavior

```
public SwipeDismissBehavior()
```

## Public methods

### canSwipeDismissView

```
public boolean canSwipeDismissView(View view)
```

Called when the user's input indicates that they want to swipe the given view.

| Parameters |
|---|---|
| `View view` | View the user is attempting to swipe |

| Returns |
|---|---|
| `boolean` | true if the view can be dismissed via swiping, false otherwise |

### getDragState

```
public int getDragState()
```

Retrieve the current drag state of this behavior. This will return one of `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_IDLE()`, `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_DRAGGING()` or `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#STATE_SETTLING()`.

| Returns |
|---|---|
| `int` | The current drag state |

### getListener

```
public SwipeDismissBehavior.OnDismissListener getListener()
```

### onInterceptTouchEvent

```
public boolean onInterceptTouchEvent(
    CoordinatorLayout parent,
    V child,
    MotionEvent event
)
```

### onLayoutChild

```
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)
```

### onTouchEvent

```
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event)
```

### setDragDismissDistance

```
public void setDragDismissDistance(float distance)
```

Set the threshold for telling if a view has been dragged enough to be dismissed.

| Parameters |
|---|---|
| `float distance` | a ratio of a view's width, values are clamped to 0 \>= x \<= 1f; |

### setEndAlphaSwipeDistance

```
public void setEndAlphaSwipeDistance(float fraction)
```

The maximum swipe distance for the view's alpha is modified.

| Parameters |
|---|---|
| `float fraction` | the distance as a fraction of the view's width. |

### setListener

```
public void setListener(SwipeDismissBehavior.OnDismissListener listener)
```

Set the listener to be used when a dismiss event occurs.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior.OnDismissListener listener` | the listener to use. |

### setSensitivity

```
public void setSensitivity(float sensitivity)
```

Set the sensitivity used for detecting the start of a swipe. This only takes effect if no touch handling has occurred yet.

| Parameters |
|---|---|
| `float sensitivity` | Multiplier for how sensitive we should be about detecting the start of a drag. Larger values are more sensitive. 1.0f is normal. |

### setStartAlphaSwipeDistance

```
public void setStartAlphaSwipeDistance(float fraction)
```

The minimum swipe distance before the view's alpha is modified.

| Parameters |
|---|---|
| `float fraction` | the distance as a fraction of the view's width. |

### setSwipeDirection

```
public void setSwipeDirection(int direction)
```

Sets the swipe direction for this behavior.

| Parameters |
|---|---|
| `int direction` | one of the `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_START_TO_END()`, `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_END_TO_START()` or `https://developer.android.com/reference/com/google/android/material/behavior/SwipeDismissBehavior#SWIPE_DIRECTION_ANY()` |