ExpandableBehavior

public abstract class ExpandableBehavior


Base Behavior for views that can react to an ExpandableWidget's setExpanded state changes.

Summary

Public constructors

ExpandableBehavior(Context context, AttributeSet attrs)

Public methods

static T
<T extends ExpandableBehavior> from(View view, Class<T> klass)

A utility function to get the ExpandableBehavior attached to the view.

abstract boolean
layoutDependsOn(CoordinatorLayout parent, View child, View dependency)
boolean
onDependentViewChanged(
    CoordinatorLayout parent,
    View child,
    View dependency
)
boolean
onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection)

Protected methods

ExpandableWidget
findExpandableWidget(CoordinatorLayout parent, View child)
abstract boolean
onExpandedStateChange(
    View dependency,
    View child,
    boolean expanded,
    boolean animated
)

Reacts to a change in expanded state.

Public constructors

ExpandableBehavior

public ExpandableBehavior()

ExpandableBehavior

public ExpandableBehavior(Context context, AttributeSet attrs)

Public methods

from

public static T <T extends ExpandableBehavior> from(View view, Class<T> klass)

A utility function to get the ExpandableBehavior attached to the view.

Parameters
View view

The View that the ExpandableBehavior is attached to.

Class<T> klass

The expected Class of the attached ExpandableBehavior.

Returns
T

The ExpandableBehavior attached to the view.

layoutDependsOn

public abstract boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency)

onDependentViewChanged

public boolean onDependentViewChanged(
    CoordinatorLayout parent,
    View child,
    View dependency
)

onLayoutChild

public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection)

Protected methods

findExpandableWidget

protected ExpandableWidget findExpandableWidget(CoordinatorLayout parent, View child)

onExpandedStateChange

protected abstract boolean onExpandedStateChange(
    View dependency,
    View child,
    boolean expanded,
    boolean animated
)

Reacts to a change in expanded state. This callback is guaranteed to be called only once even if setExpanded is called multiple times with the same value. Upon configuration change, this callback is called with animated set to false.

Parameters
View dependency

the com.google.android.material.expandable.ExpandableWidget dependency containing the new expanded state.

View child

the view that should react to the change in expanded state.

boolean expanded

the new expanded state.

boolean animated

true if setExpanded was called, false if restoring from a configuration change.

Returns
boolean

true if the Behavior changed the child view's size or position, false otherwise.