HideBottomViewOnScrollBehavior

public class HideBottomViewOnScrollBehavior<V extends View>

Known direct subclasses
BottomAppBar.Behavior

Behavior designed for use with BottomAppBar instances.


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

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

State of the bottom view when it's scrolled down.

static final int

State of the bottom view when it's scrolled up.

Public constructors

HideBottomViewOnScrollBehavior(Context context, AttributeSet attrs)

Public methods

void

Adds a listener to be notified of bottom 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.

boolean

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

boolean

Returns true if the current state is scrolled down.

boolean

Returns true if the current state is scrolled up.

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
setAdditionalHiddenOffsetY(V child, int offset)

Sets an additional offset for the y position used to hide the view.

void
slideDown(V child)

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

void
slideDown(V child, boolean animate)

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

void
slideUp(V child)

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

void
slideUp(V child, boolean animate)

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

Constants

STATE_SCROLLED_DOWN

public static final int STATE_SCROLLED_DOWN = 1

State of the bottom view when it's scrolled down.

STATE_SCROLLED_UP

public static final int STATE_SCROLLED_UP = 2

State of the bottom view when it's scrolled up.

Public constructors

HideBottomViewOnScrollBehavior

public HideBottomViewOnScrollBehavior()

HideBottomViewOnScrollBehavior

public HideBottomViewOnScrollBehavior(Context context, AttributeSet attrs)

Public methods

addOnScrollStateChangedListener

public void addOnScrollStateChangedListener(
    HideBottomViewOnScrollBehavior.OnScrollStateChangedListener listener
)

Adds a listener to be notified of bottom view scroll state changes.

Parameters
HideBottomViewOnScrollBehavior.OnScrollStateChangedListener listener

The listener to notify when bottom 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.

isDisabledOnTouchExploration

public boolean isDisabledOnTouchExploration()

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

isScrolledDown

public boolean isScrolledDown()

Returns true if the current state is scrolled down.

isScrolledUp

public boolean isScrolledUp()

Returns true if the current state is scrolled up.

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(
    HideBottomViewOnScrollBehavior.OnScrollStateChangedListener listener
)

Removes a previously added listener.

Parameters
HideBottomViewOnScrollBehavior.OnScrollStateChangedListener listener

The listener to remove.

setAdditionalHiddenOffsetY

public void setAdditionalHiddenOffsetY(V child, int offset)

Sets an additional offset for the y position 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

slideDown

public void slideDown(V child)

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

slideDown

public void slideDown(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.

slideUp

public void slideUp(V child)

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

slideUp

public void slideUp(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.