# HideViewOnScrollBehavior

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

*** ** * ** ***


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

<br />

*** ** * ** ***

The Behavior for a View within a CoordinatorLayout to hide the view off of the edge of the screen when scrolling down, and show it when scrolling up.

Supports hiding the View off of three screen edges: `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_RIGHT()`, `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_BOTTOM()`, and `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_LEFT()`.

If Touch Exploration is enabled, the hide on scroll behavior should be disabled until Touch Exploration is disabled. Ensure that the content is not obscured due to disabling this behavior by adding padding to the content.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener` Interface definition for a listener to be notified when the bottom view scroll state changes. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_BOTTOM() = 1` The sheet slides out from the bottom edge of the screen. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_LEFT() = 2` The sheet slides out from the left edge of the screen. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#EDGE_RIGHT() = 0` The sheet slides out from the right edge of the screen. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#STATE_SCROLLED_IN() = 2` State of the view when it's scrolled in. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#STATE_SCROLLED_OUT() = 1` State of the view when it's scrolled out. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#HideViewOnScrollBehavior()()` |
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#HideViewOnScrollBehavior(int)(int viewEdge)` |
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#HideViewOnScrollBehavior(Context,AttributeSet)(Context context, AttributeSet attrs)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#addOnScrollStateChangedListener(com.google.android.material.behavior.HideViewOnScrollBehavior.OnScrollStateChangedListener)( https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener listener )` Adds a listener to be notified of View scroll state changes. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#clearOnScrollStateChangedListeners()()` Remove all previously added `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener`s. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#disableOnTouchExploration(boolean)(boolean disableOnTouchExploration)` Sets whether or not to disable this behavior if touch exploration is enabled. |
| `static https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior<V>` | `<V extends View> https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#from(V)(V view)` A utility function to get the `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior` associated with the ` view`. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#isDisabledOnTouchExploration()()` Returns whether or not this behavior is disabled if touch exploration is enabled. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#isScrolledIn()()` Returns true if the current state is scrolled in. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#isScrolledOut()()` Returns true if the current state is scrolled out. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#onLayoutChild(CoordinatorLayout,V,int)(CoordinatorLayout parent, V child, int layoutDirection)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#onNestedScroll(CoordinatorLayout,V,View,int,int,int,int,int,int[])( CoordinatorLayout coordinatorLayout, V child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, int[] consumed )` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#onStartNestedScroll(CoordinatorLayout,V,View,View,int,int)( CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int nestedScrollAxes, int type )` |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#removeOnScrollStateChangedListener(com.google.android.material.behavior.HideViewOnScrollBehavior.OnScrollStateChangedListener)( https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener listener )` Removes a previously added listener. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#setAdditionalHiddenOffset(V,int)(V child, int offset)` Sets an additional offset used to hide the view. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#setViewEdge(int)(int viewEdge)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#slideIn(V)(V child)` Performs an animation that will slide the child from its current position to be totally on the screen. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#slideIn(V,boolean)(V child, boolean animate)` Slides the child with or without animation from its current position to be totally on the screen. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#slideOut(V)(V child)` Performs an animation that will slide the child from it's current position to be totally off the screen. |
| `void` | `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior#slideOut(V,boolean)(V child, boolean animate)` Slides the child with or without animation from its current position to be totally off the screen. |

## Constants

### EDGE_BOTTOM

```
public static final int EDGE_BOTTOM = 1
```

The sheet slides out from the bottom edge of the screen.

### EDGE_LEFT

```
public static final int EDGE_LEFT = 2
```

The sheet slides out from the left edge of the screen.

### EDGE_RIGHT

```
public static final int EDGE_RIGHT = 0
```

The sheet slides out from the right edge of the screen.

### STATE_SCROLLED_IN

```
public static final int STATE_SCROLLED_IN = 2
```

State of the view when it's scrolled in.

### STATE_SCROLLED_OUT

```
public static final int STATE_SCROLLED_OUT = 1
```

State of the view when it's scrolled out.

## Public constructors

### HideViewOnScrollBehavior

```
public HideViewOnScrollBehavior()
```

### HideViewOnScrollBehavior

```
public HideViewOnScrollBehavior(int viewEdge)
```

### HideViewOnScrollBehavior

```
public HideViewOnScrollBehavior(Context context, AttributeSet attrs)
```

## Public methods

### addOnScrollStateChangedListener

```
public void addOnScrollStateChangedListener(
    HideViewOnScrollBehavior.OnScrollStateChangedListener listener
)
```

Adds a listener to be notified of View scroll state changes.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener listener` | The listener to notify when View scroll state changes. |

### clearOnScrollStateChangedListeners

```
public void clearOnScrollStateChangedListeners()
```

Remove all previously added `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener`s.

### disableOnTouchExploration

```
public void disableOnTouchExploration(boolean disableOnTouchExploration)
```

Sets whether or not to disable this behavior if touch exploration is enabled.

### from

```
public static HideViewOnScrollBehavior<V> <V extends View> from(V view)
```

A utility function to get the `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior` associated with the `
view`.

| Parameters |
|---|---|
| `V view` | The View with `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior<V>` | The `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior` associated with the `view`. |

### isDisabledOnTouchExploration

```
public boolean isDisabledOnTouchExploration()
```

Returns whether or not this behavior is disabled if touch exploration is enabled.

### isScrolledIn

```
public boolean isScrolledIn()
```

Returns true if the current state is scrolled in.

### isScrolledOut

```
public boolean isScrolledOut()
```

Returns true if the current state is scrolled out.

### onLayoutChild

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

### onNestedScroll

```
public void onNestedScroll(
    CoordinatorLayout coordinatorLayout,
    V child,
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type,
    int[] consumed
)
```

### onStartNestedScroll

```
public boolean onStartNestedScroll(
    CoordinatorLayout coordinatorLayout,
    V child,
    View directTargetChild,
    View target,
    int nestedScrollAxes,
    int type
)
```

### removeOnScrollStateChangedListener

```
public void removeOnScrollStateChangedListener(
    HideViewOnScrollBehavior.OnScrollStateChangedListener listener
)
```

Removes a previously added listener.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/behavior/HideViewOnScrollBehavior.OnScrollStateChangedListener listener` | The listener to remove. |

### setAdditionalHiddenOffset

```
public void setAdditionalHiddenOffset(V child, int offset)
```

Sets an additional offset used to hide the view.

| Parameters |
|---|---|
| `V child` | the child view that is hidden by this behavior |
| `int offset` | the additional offset in pixels that should be added when the view slides away |

### setViewEdge

```
public void setViewEdge(int viewEdge)
```

### slideIn

```
public void slideIn(V child)
```

Performs an animation that will slide the child from its current position to be totally on the screen.

### slideIn

```
public void slideIn(V child, boolean animate)
```

Slides the child with or without animation from its current position to be totally on the screen.

| Parameters |
|---|---|
| `boolean animate` | `true` to slide with animation. |

### slideOut

```
public void slideOut(V child)
```

Performs an animation that will slide the child from it's current position to be totally off the screen.

### slideOut

```
public void slideOut(V child, boolean animate)
```

Slides the child with or without animation from its current position to be totally off the screen.

| Parameters |
|---|---|
| `boolean animate` | `true` to slide with animation. |