HideViewOnScrollBehavior

public class HideViewOnScrollBehavior<V extends View>


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: EDGE_RIGHT, EDGE_BOTTOM, and 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

Interface definition for a listener to be notified when the bottom view scroll state changes.

Constants

static final int

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

static final int

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

static final int

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

static final int

State of the view when it's scrolled in.

static final int

State of the view when it's scrolled out.

Public constructors

HideViewOnScrollBehavior(Context context, AttributeSet attrs)

Public methods

void

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

void

Remove all previously added OnScrollStateChangedListeners.

void
disableOnTouchExploration(boolean disableOnTouchExploration)

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

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

A utility function to get the HideViewOnScrollBehavior associated with the view.

boolean

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

boolean

Returns true if the current state is scrolled in.

boolean

Returns true if the current state is scrolled out.

boolean
onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection)
void
onNestedScroll(
    CoordinatorLayout coordinatorLayout,
    V child,
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type,
    int[] consumed
)
boolean
onStartNestedScroll(
    CoordinatorLayout coordinatorLayout,
    V child,
    View directTargetChild,
    View target,
    int nestedScrollAxes,
    int type
)
void

Removes a previously added listener.

void
setAdditionalHiddenOffset(V child, int offset)

Sets an additional offset used to hide the view.

void
setViewEdge(int viewEdge)
void
slideIn(V child)

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

void
slideIn(V child, boolean animate)

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

void
slideOut(V child)

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

void
slideOut(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
HideViewOnScrollBehavior.OnScrollStateChangedListener listener

The listener to notify when View scroll state changes.

clearOnScrollStateChangedListeners

public void clearOnScrollStateChangedListeners()

Remove all previously added OnScrollStateChangedListeners.

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 HideViewOnScrollBehavior associated with the view.

Parameters
V view

The View with HideViewOnScrollBehavior.

Returns
HideViewOnScrollBehavior<V>

The 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
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.