Google is committed to advancing racial equity for Black communities. See how.

Behavior

abstract class Behavior<V : View!>
kotlin.Any
   ↳ androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior

Interaction behavior plugin for child views of CoordinatorLayout.

A Behavior implements one or more interactions that a user can take on a child view. These interactions may include drags, swipes, flings, or any other gestures.

Summary

Public constructors

Default constructor for instantiating Behaviors.

<init>(context: Context!, attrs: AttributeSet!)

Default constructor for inflating Behaviors from layout.

Public methods
open Boolean
blocksInteractionBelow(@NonNull parent: CoordinatorLayout, @NonNull child: V)

Determine whether interaction with views behind the given child in the child order should be blocked.

open Boolean
getInsetDodgeRect(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull rect: Rect)

Called when a view is set to dodge view insets.

open Int
getScrimColor(@NonNull parent: CoordinatorLayout, @NonNull child: V)

Supply a scrim color that will be painted behind the associated child view.

open Float
getScrimOpacity(@NonNull parent: CoordinatorLayout, @NonNull child: V)

Determine the current opacity of the scrim behind a given child view

open static Any?
getTag(@NonNull child: View)

Get the behavior-specific tag object with the given child view.

open Boolean
layoutDependsOn(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View)

Determine whether the supplied child view has another specific sibling view as a layout dependency.

open WindowInsetsCompat
onApplyWindowInsets(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull insets: WindowInsetsCompat)

Called when the window insets have changed.

open Unit

Called when the Behavior has been attached to a LayoutParams instance.

open Boolean
onDependentViewChanged(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View)

Respond to a change in a child's dependent view

open Unit
onDependentViewRemoved(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull dependency: View)

Respond to a child's dependent view being removed.

open Unit

Called when the Behavior has been detached from its holding LayoutParams instance.

open Boolean
onInterceptTouchEvent(@NonNull parent: CoordinatorLayout, @NonNull child: V, @NonNull ev: MotionEvent)

Respond to CoordinatorLayout touch events before they are dispatched to child views.

open Boolean
onLayoutChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, layoutDirection: Int)

Called when the parent CoordinatorLayout is about the lay out the given child view.

open Boolean
onMeasureChild(@NonNull parent: CoordinatorLayout, @NonNull child: V, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int)

Called when the parent CoordinatorLayout is about to measure the given child view.

open Boolean
onNestedFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float, consumed: Boolean)

Called when a nested scrolling child is starting a fling or an action that would be a fling.

open Boolean
onNestedPreFling(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, velocityX: Float, velocityY: Float)

Called when a nested scrolling child is about to start a fling.

open Unit
onNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray)

open Unit
onNestedPreScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int)

Called when a nested scroll in progress is about to update, before the target has consumed any of the scrolled distance.

open Unit
onNestedScroll(@NonNull coordinatorLayout: CoordinatorLayout, @NonNull child: V, @NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: