CoordinatorLayout
class CoordinatorLayout : ViewGroup, NestedScrollingParent2, NestedScrollingParent3
kotlin.Any | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | androidx.coordinatorlayout.widget.CoordinatorLayout |
CoordinatorLayout is a super-powered FrameLayout
.
CoordinatorLayout is intended for two primary use cases:
- As a top-level application decor or chrome layout
- As a container for a specific interaction with one or more child views
By specifying Behaviors
for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another. View classes can specify a default behavior when used as a child of a CoordinatorLayout by implementing the AttachedBehavior
interface.
Behaviors may be used to implement a variety of interactions and additional layout modifications ranging from sliding drawers and panels to swipe-dismissable elements and buttons that stick to other elements as they move and animate.
Children of a CoordinatorLayout may have an anchor
. This view id must correspond to an arbitrary descendant of the CoordinatorLayout, but it may not be the anchored child itself or a descendant of the anchored child. This can be used to place floating views relative to other arbitrary content panes.
Children can specify insetEdge
to describe how the view insets the CoordinatorLayout. Any child views which are set to dodge the same inset edges by dodgeInsetEdges
will be moved appropriately so that the views do not overlap.
Summary
Nested types |
---|
interface CoordinatorLayout.AttachedBehavior |
abstract class CoordinatorLayout.Behavior<V : View?> Interaction behavior plugin for child views of |
@Retention(value = RetentionPolicy.RUNTIME) This annotation is deprecated. Use |
Parameters describing the desired layout for a child of a |
protected class CoordinatorLayout.SavedState : AbsSavedState |
Public constructors |
---|
CoordinatorLayout(context: Context) |
CoordinatorLayout(context: Context, attrs: AttributeSet?) |
CoordinatorLayout( |
Public functions |
|
---|---|
Unit |
Allows the caller to manually dispatch |
Boolean |
dispatchKeyEvent(event: KeyEvent) |
Boolean |
doViewsOverlap(first: View, second: View) Check whether two views overlap each other. |
CoordinatorLayout.LayoutParams! |
generateLayoutParams(attrs: AttributeSet!) |
(Mutable)List<View!> |
getDependencies(child: View) Returns a new list containing the views on which the provided view depends. |
(Mutable)List<View!> |
getDependents(child: View) Returns a new list of views which depend on the provided view. |
Int |
|
Drawable? |
Gets the drawable used to draw in the insets area for the status bar. |
Boolean |
isPointInChildBounds(child: View, x: Int, y: Int) Check if a given point in the CoordinatorLayout's coordinates are within the view bounds of the given direct child view. |
Unit |
|
Unit |
|
Unit |
|
Boolean |
|
Unit |
onLayoutChild(child: View, layoutDirection: Int) Called to lay out each individual child view unless a |
Unit |
onMeasureChild( Called to measure each individual child view unless a |
Boolean |
onNestedFling( |
Boolean |
onNestedPreFling(target: View!, velocityX: Float, velocityY: Float) |
Unit |
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray) |
Unit |
React to a nested scroll in progress before the target view consumes a portion of the scroll. |
Unit |
|
Unit |
onNestedScroll( React to a nested scroll in progress. |
Unit |
onNestedScroll( React to a nested scroll in progress. |
Unit |
onNestedScrollAccepted(child: View, target: View, axes: Int) |
Unit |
onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int) React to the successful claiming of a nested scroll operation. |
Boolean |
onStartNestedScroll(child: View, target: View, axes: Int) |
Boolean |
onStartNestedScroll(child: View, target: View, axes: Int, type: Int) React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
Unit |
onStopNestedScroll(target: View) |
Unit |
onStopNestedScroll(target: View, type: Int) React to a nested scroll operation ending. |
Boolean |
onTouchEvent(ev: MotionEvent!) |
Boolean |
requestChildRectangleOnScreen( |
Unit |
requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) |
Unit |
setFitsSystemWindows(fitSystemWindows: Boolean) |
Unit |
setOnHierarchyChangeListener( |
Unit |
Set a drawable to draw in the insets area for the status bar. |
Unit |
setStatusBarBackgroundColor(color: @ColorInt Int) Set a drawable to draw in the insets area for the status bar. |
Unit |
setStatusBarBackgroundResource(resId: @DrawableRes Int) Set a drawable to draw in the insets area for the status bar. |
Unit |
setVisibility(visibility: Int) |
Protected functions |
|
---|---|
Boolean |
|
Boolean |
|
Unit |
|
CoordinatorLayout.LayoutParams! |
|
CoordinatorLayout.LayoutParams! |
|
Int |
|
Int |
|
Unit |
|
Unit |
|
Unit |
onRestoreInstanceState(state: Parcelable!) |
Parcelable |
|
Boolean |
verifyDrawable(who: Drawable) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
CoordinatorLayout
CoordinatorLayout(
context: Context,
attrs: AttributeSet?,
defStyleAttr: @AttrRes Int
)
Public functions
dispatchDependentViewsChanged
fun dispatchDependentViewsChanged(view: View): Unit
Allows the caller to manually dispatch onDependentViewChanged
to the associated Behavior
instances of views which depend on the provided View
.
You should not normally need to call this method as the it will be automatically done when the view has changed.
Parameters | |
---|---|
view: View |
the View to find dependents of to dispatch the call. |
doViewsOverlap
fun doViewsOverlap(first: View, second: View): Boolean
Check whether two views overlap each other. The views need to be descendants of this CoordinatorLayout
in the view hierarchy.
Returns | |
---|---|
Boolean |
true if both views are visible and overlap each other |
generateLayoutParams
fun generateLayoutParams(attrs: AttributeSet!): CoordinatorLayout.LayoutParams!
getDependencies
fun getDependencies(child: View): (Mutable)List<View!>
Returns a new list containing the views on which the provided view depends.
Parameters | |
---|---|
child: View |
the view to find dependencies for |
getDependents
fun getDependents(child: View): (Mutable)List<View!>
Returns a new list of views which depend on the provided view.
Parameters | |
---|---|
child: View |
the view to find dependents of |
getStatusBarBackground
fun getStatusBarBackground(): Drawable?
Gets the drawable used to draw in the insets area for the status bar.
Returns | |
---|---|
Drawable? |
The status bar background drawable, or null if none set |
isPointInChildBounds
fun isPointInChildBounds(child: View, x: Int, y: Int): Boolean
Check if a given point in the CoordinatorLayout's coordinates are within the view bounds of the given direct child view.
Parameters | |
---|---|
child: View |
child view to test |
x: Int |
X coordinate to test, in the CoordinatorLayout's coordinate system |
y: Int |
Y coordinate to test, in the CoordinatorLayout's coordinate system |
Returns | |
---|---|
Boolean |
true if the point is within the child view's bounds, false otherwise |
onLayoutChild
fun onLayoutChild(child: View, layoutDirection: Int): Unit
Called to lay out each individual child view unless a Behavior
is present. The Behavior may choose to delegate child measurement to this method.
Parameters | |
---|---|
child: View |
child view to lay out |
layoutDirection: Int |
the resolved layout direction for the CoordinatorLayout, such as |
onMeasureChild
fun onMeasureChild(
child: View,
parentWidthMeasureSpec: Int,
widthUsed: Int,
parentHeightMeasureSpec: Int,
heightUsed: Int
): Unit
Called to measure each individual child view unless a Behavior
is present. The Behavior may choose to delegate child measurement to this method.
Parameters | |
---|---|
child: View |
the child to measure |
parentWidthMeasureSpec: Int |
the width requirements for this view |
widthUsed: Int |
extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec: Int |
the height requirements for this view |
heightUsed: Int |
extra space that has been used up by the parent vertically (possibly by other children of the parent) |
onNestedFling
fun onNestedFling(
target: View!,
velocityX: Float,
velocityY: Float,
consumed: Boolean
): Boolean
onNestedPreScroll
fun onNestedPreScroll(
target: View,
dx: Int,
dy: Int,
consumed: IntArray,
type: Int
): Unit
React to a nested scroll in progress before the target view consumes a portion of the scroll.
When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.
onNestedPreScroll
is called when a nested scrolling child invokes dispatchNestedPreScroll
. The implementation should report how any pixels of the scroll reported by dx, dy were consumed in the consumed
array. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.
Parameters | |
---|---|
target: View |
View that initiated the nested scroll |
dx: Int |
Horizontal scroll distance in pixels |
dy: Int |
Vertical scroll distance in pixels |
consumed: IntArray |
Output. The horizontal and vertical scroll distance consumed by this parent |
type: Int |
the type of input which cause this scroll event |
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int
): Unit
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
type: Int
): Unit
React to a nested scroll in progress.
This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true
for a call to onStartNestedScroll
.
Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
Parameters | |
---|---|
target: View |
The descendent view controlling the nested scroll |
dxConsumed: Int |
Horizontal scroll distance in pixels already consumed by target |
dyConsumed: Int |
Vertical scroll distance in pixels already consumed by target |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed: Int |
Vertical scroll distance in pixels not consumed by target |
type: Int |
the type of input which cause this scroll event |
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
type: Int,
consumed: IntArray
): Unit
React to a nested scroll in progress.
This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true
for a call to onStartNestedScroll
.
Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
This method is called when a nested scrolling child invokes dispatchNestedScroll
} or one of methods it overloads.
An implementation must report how many pixels of the the x and y scroll distances were consumed by this nested scrolling parent by adding the consumed distances to the consumed
parameter. If this View also implements NestedScrollingChild3
, consumed
should also be passed up to it's nested scrolling parent so that the parent may also add any scroll distance it consumes. Index 0 corresponds to dx and index 1 corresponds to dy.
Parameters | |
---|---|
target: View |
The descendant view controlling the nested scroll |
dxConsumed: Int |
Horizontal scroll distance in pixels already consumed by target |
dyConsumed: Int |
Vertical scroll distance in pixels already consumed by target |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed: Int |
Vertical scroll distance in pixels not consumed by target |
type: Int |
the type of input which cause this scroll event |
consumed: IntArray |
Output. Upon this method returning, will contain the scroll distances consumed by this nested scrolling parent and the scroll distances consumed by any other parent up the view hierarchy |
See also | |
---|---|
dispatchNestedScroll |
onNestedScrollAccepted
fun onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int): Unit
React to the successful claiming of a nested scroll operation.
This method will be called after onStartNestedScroll
returns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclass's implementation of this method if one is present.
Parameters | |
---|---|
child: View |
Direct child of this ViewParent containing target |
target: View |
View that initiated the nested scroll |
axes: Int |
Flags consisting of |
type: Int |
the type of input which cause this scroll event |
See also | |
---|---|
onStartNestedScroll |
|
onStopNestedScroll |
onStartNestedScroll
fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean
React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.
This method will be called in response to a descendant view invoking startNestedScroll
. Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning true
.
This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to onStopNestedScroll
.
Parameters | |
---|---|
child: View |
Direct child of this ViewParent containing target |
target: View |
View that initiated the nested scroll |
axes: Int |
Flags consisting of |
type: Int |
the type of input which cause this scroll event |
Returns | |
---|---|
Boolean |
true if this ViewParent accepts the nested scroll operation |
onStopNestedScroll
fun onStopNestedScroll(target: View, type: Int): Unit
React to a nested scroll operation ending.
Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a ACTION_UP
or ACTION_CANCEL
event. Implementations of this method should always call their superclass's implementation of this method if one is present.
requestChildRectangleOnScreen
fun requestChildRectangleOnScreen(
child: View!,
rectangle: Rect!,
immediate: Boolean
): Boolean
requestDisallowInterceptTouchEvent
fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit
setOnHierarchyChangeListener
fun setOnHierarchyChangeListener(
onHierarchyChangeListener: ViewGroup.OnHierarchyChangeListener!
): Unit
setStatusBarBackground
fun setStatusBarBackground(bg: Drawable?): Unit
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
Parameters | |
---|---|
bg: Drawable? |
Background drawable to draw behind the status bar |
setStatusBarBackgroundColor
fun setStatusBarBackgroundColor(color: @ColorInt Int): Unit
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
setStatusBarBackgroundResource
fun setStatusBarBackgroundResource(resId: @DrawableRes Int): Unit
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
Parameters | |
---|---|
resId: @DrawableRes Int |
Resource id of a background drawable to draw behind the status bar |
Protected functions
generateDefaultLayoutParams
protected fun generateDefaultLayoutParams(): CoordinatorLayout.LayoutParams!
generateLayoutParams
protected fun generateLayoutParams(p: ViewGroup.LayoutParams!): CoordinatorLayout.LayoutParams!