CoordinatorLayout

public class CoordinatorLayout
extends ViewGroup implements NestedScrollingParent2, NestedScrollingParent3

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.coordinatorlayout.widget.CoordinatorLayout


CoordinatorLayout is a super-powered FrameLayout.

CoordinatorLayout is intended for two primary use cases:

  1. As a top-level application decor or chrome layout
  2. 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 using the CoordinatorLayout.DefaultBehavior annotation.

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 CoordinatorLayout.LayoutParams.insetEdge to describe how the view insets the CoordinatorLayout. Any child views which are set to dodge the same inset edges by CoordinatorLayout.LayoutParams.dodgeInsetEdges will be moved appropriately so that the views do not overlap.

Summary

Nested classes

interface CoordinatorLayout.AttachedBehavior

Defines the default attached CoordinatorLayout.Behavior of a View class

When writing a custom view, implement this interface to return the default behavior when used as a direct child of an CoordinatorLayout

class CoordinatorLayout.Behavior<V extends View>

Interaction behavior plugin for child views of CoordinatorLayout

@interface CoordinatorLayout.DefaultBehavior

This @interface is deprecated. Use CoordinatorLayout.AttachedBehavior instead  

class CoordinatorLayout.LayoutParams

Parameters describing the desired layout for a child of a CoordinatorLayout

class CoordinatorLayout.SavedState

 

Inherited constants

Inherited fields

Public constructors

CoordinatorLayout(Context context)
CoordinatorLayout(Context context, AttributeSet attrs)
CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

void dispatchDependentViewsChanged(View view)

Allows the caller to manually dispatch CoordinatorLayout.Behavior.onDependentViewChanged(CoordinatorLayout, View, View) to the associated CoordinatorLayout.Behavior instances of views which depend on the provided View.

boolean doViewsOverlap(View first, View second)

Check whether two views overlap each other.

CoordinatorLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
List<View> getDependencies(View child)

Returns the list of views which the provided view depends on.

List<View> getDependents(View child)

Returns the list of views which depend on the provided view.

int getNestedScrollAxes()
Drawable getStatusBarBackground()

Gets the drawable used to draw in the insets area for the status bar.

boolean isPointInChildBounds(View child, int x, int y)

Check if a given point in the CoordinatorLayout's coordinates are within the view bounds of the given direct child view.

void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas c)
boolean onInterceptTouchEvent(MotionEvent ev)
void onLayoutChild(View child, int layoutDirection)

Called to lay out each individual child view unless a Behavior is present.

void onMeasureChild(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)

Called to measure each individual child view unless a Behavior is present.

boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed)
boolean onNestedPreFling(View target, float velocityX, float velocityY)
void onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void onNestedPreScroll(View target, int dx, int dy, int[] consumed, int type)

React to a nested scroll in progress before the target view consumes a portion of the scroll.

void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, int[] consumed)

React to a nested scroll in progress.

void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type)

React to a nested scroll in progress.

void onNestedScrollAccepted(View child, View target, int axes, int type)

React to the successful claiming of a nested scroll operation.

void onNestedScrollAccepted(View child, View target, int axes)
boolean onStartNestedScroll(View child, View target, int axes, int type)

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

boolean onStartNestedScroll(View child, View target, int nestedScrollAxes)
void onStopNestedScroll(View target)
void onStopNestedScroll(View target, int type)

React to a nested scroll operation ending.

boolean onTouchEvent(MotionEvent ev)
boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)
void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
void setFitsSystemWindows(boolean fitSystemWindows)
void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener)
void setStatusBarBackground(Drawable bg)

Set a drawable to draw in the insets area for the status bar.

void setStatusBarBackgroundColor(int color)

Set a drawable to draw in the insets area for the status bar.

void setStatusBarBackgroundResource(int resId)

Set a drawable to draw in the insets area for the status bar.

void setVisibility(int visibility)

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
boolean drawChild(Canvas canvas, View child, long drawingTime)
void drawableStateChanged()
CoordinatorLayout.LayoutParams generateDefaultLayoutParams()
CoordinatorLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
int getSuggestedMinimumHeight()
int getSuggestedMinimumWidth()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()
boolean verifyDrawable(Drawable who)

Inherited methods