Skip to content

Most visited

Recently visited

navigation

CoordinatorLayout

public class CoordinatorLayout
extends ViewGroup implements NestedScrollingParent

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.design.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 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 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 classes

class CoordinatorLayout.Behavior<V extends View>

Interaction behavior plugin for child views of CoordinatorLayout

@interface CoordinatorLayout.DefaultBehavior

Defines the default CoordinatorLayout.Behavior of a View class. 

class CoordinatorLayout.LayoutParams

Parameters describing the desired layout for a child of a CoordinatorLayout

class CoordinatorLayout.SavedState

 

Inherited XML attributes

From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

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 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)

Returns a new set of layout parameters based on the supplied attributes set.

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()

Return the current axes of nested scrolling for this ViewGroup.

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()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onDraw(Canvas c)

Implement this to do your drawing.

boolean onInterceptTouchEvent(MotionEvent ev)

Implement this method to intercept all touch screen motion events.

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)

Request a fling from a nested scroll.

boolean onNestedPreFling(View target, float velocityX, float velocityY)

React to a nested fling before the target view consumes it.

void onNestedPreScroll(View target, int dx, int dy, int[] consumed)

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)

React to a nested scroll in progress.

void onNestedScrollAccepted(View child, View target, int nestedScrollAxes)

React to the successful claiming of a nested scroll operation.

boolean onStartNestedScroll(View child, View target, int nestedScrollAxes)

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

void onStopNestedScroll(View target)

React to a nested scroll operation ending.

boolean onTouchEvent(MotionEvent ev)

Implement this method to handle touch screen motion events.

boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)

Called when a child of this group wants a particular rectangle to be positioned onto the screen.

void requestDisallowInterceptTouchEvent(boolean disallowIntercept)

Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

void setFitsSystemWindows(boolean fitSystemWindows)

Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of fitSystemWindows(Rect) will be executed.

void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener)

Register a callback to be invoked when a child is added to or removed from this view.

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)

Set the enabled state of this view.

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
boolean drawChild(Canvas canvas, View child, long drawingTime)

Draw one child of this View Group.

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

CoordinatorLayout.LayoutParams generateDefaultLayoutParams()

Returns a set of default layout parameters.

CoordinatorLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)

Returns a safe set of layout parameters based on the supplied layout params.

int getSuggestedMinimumHeight()

Returns the suggested minimum height that the view should use.

int getSuggestedMinimumWidth()

Returns the suggested minimum width that the view should use.

void onLayout(boolean changed, int l, int t, int r, int b)

Called from layout when this view should assign a size and position to each of its children.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

boolean verifyDrawable(Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited methods

From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.support.v4.view.NestedScrollingParent

Public constructors

CoordinatorLayout

CoordinatorLayout (Context context)

Parameters
context Context

CoordinatorLayout

CoordinatorLayout (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

CoordinatorLayout

CoordinatorLayout (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

Public methods

dispatchDependentViewsChanged

void dispatchDependentViewsChanged (View view)

Allows the caller to manually dispatch onDependentViewChanged(CoordinatorLayout, View, View) to the associated CoordinatorLayout.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

boolean doViewsOverlap (View first, 
                View second)

Check whether two views overlap each other. The views need to be descendants of this CoordinatorLayout in the view hierarchy.

Parameters
first View: first child view to test
second View: second child view to test
Returns
boolean true if both views are visible and overlap each other

generateLayoutParams

CoordinatorLayout.LayoutParams generateLayoutParams (AttributeSet attrs)

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs AttributeSet: the attributes to build the layout parameters from
Returns
CoordinatorLayout.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

getDependencies

List<View> getDependencies (View child)

Returns the list of views which the provided view depends on. Do not store this list as its contents may not be valid beyond the caller.

Parameters
child View: the view to find dependencies for.
Returns
List<View> the list of views which child depends on.

getDependents

List<View> getDependents (View child)

Returns the list of views which depend on the provided view. Do not store this list as its contents may not be valid beyond the caller.

Parameters
child View: the view to find dependents of.
Returns
List<View> the list of views which depend on child.

getNestedScrollAxes

int getNestedScrollAxes ()

Return the current axes of nested scrolling for this ViewGroup.

A ViewGroup returning something other than SCROLL_AXIS_NONE is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.

Returns
int Flags indicating the current axes of nested scrolling

getStatusBarBackground

Drawable getStatusBarBackground ()

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

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.

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

onAttachedToWindow

void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

onDetachedFromWindow

void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

onDraw

void onDraw (Canvas c)

Implement this to do your drawing.

Parameters
c Canvas: the canvas on which the background will be drawn

onInterceptTouchEvent

boolean onInterceptTouchEvent (MotionEvent ev)

Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

  1. You will receive the down event here.
  2. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
  3. For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
  4. If you return true from here, you will not receive any following events: the target view will receive the same event but with the action ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.

Parameters
ev MotionEvent: The motion event being dispatched down the hierarchy.
Returns
boolean Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.

onLayoutChild

void onLayoutChild (View child, 
                int layoutDirection)

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 LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.

onMeasureChild

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

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

boolean onNestedFling (View target, 
                float velocityX, 
                float velocityY, 
                boolean consumed)

Request a fling from a nested scroll.

This method signifies that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

Parameters
target View: View that initiated the nested scroll
velocityX float: Horizontal velocity in pixels per second
velocityY float: Vertical velocity in pixels per second
consumed boolean: true if the child consumed the fling, false otherwise
Returns
boolean true if this parent consumed or otherwise reacted to the fling

onNestedPreFling

boolean onNestedPreFling (View target, 
                float velocityX, 
                float velocityY)

React to a nested fling before the target view consumes it.

This method siginfies that a nested scrolling child has detected a fling with the given velocity along each axis. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

If a nested scrolling parent is consuming motion as part of a pre-scroll, it may be appropriate for it to also consume the pre-fling to complete that same motion. By returning true from this method, the parent indicates that the child should not fling its own internal content as well.

Parameters
target View: View that initiated the nested scroll
velocityX float: Horizontal velocity in pixels per second
velocityY float: Vertical velocity in pixels per second
Returns
boolean true if this parent consumed the fling ahead of the target view

onNestedPreScroll

void onNestedPreScroll (View target, 
                int dx, 
                int dy, 
                int[] consumed)

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(int, int, int[], int[]). 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 int: Output. The horizontal and vertical scroll distance consumed by this parent

onNestedScroll

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

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(View, View, int).

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

onNestedScrollAccepted

void onNestedScrollAccepted (View child, 
                View target, 
                int nestedScrollAxes)

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
nestedScrollAxes int: Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both

onStartNestedScroll

boolean onStartNestedScroll (View child, 
                View target, 
                int nestedScrollAxes)

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(int). 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(View).

Parameters
child View: Direct child of this ViewParent containing target
target View: View that initiated the nested scroll
nestedScrollAxes int: Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both
Returns
boolean true if this ViewParent accepts the nested scroll operation

onStopNestedScroll

void onStopNestedScroll (View target)

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.

Parameters
target View: View that initiated the nested scroll

onTouchEvent

boolean onTouchEvent (MotionEvent ev)

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

Parameters
ev MotionEvent: The motion event.
Returns
boolean True if the event was handled, false otherwise.

requestChildRectangleOnScreen

boolean requestChildRectangleOnScreen (View child, 
                Rect rectangle, 
                boolean immediate)

Called when a child of this group wants a particular rectangle to be positioned onto the screen. ViewGroups overriding this can trust that:

  • child will be a direct child of this group
  • rectangle will be in the child's content coordinates

ViewGroups overriding this should uphold the contract:

  • nothing will change if the rectangle is already visible
  • the view port will be scrolled only just enough to make the rectangle visible
    • Parameters
      child View: The direct child making the request.
      rectangle Rect: The rectangle in the child's coordinates the child wishes to be on the screen.
      immediate boolean: True to forbid animated or delayed scrolling, false otherwise
      Returns
      boolean Whether the group scrolled to handle the operation

requestDisallowInterceptTouchEvent

void requestDisallowInterceptTouchEvent (boolean disallowIntercept)

Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.

Parameters
disallowIntercept boolean: True if the child does not want the parent to intercept touch events.

setFitsSystemWindows

void setFitsSystemWindows (boolean fitSystemWindows)

Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of fitSystemWindows(Rect) will be executed. See that method for more details.

Note that if you are providing your own implementation of fitSystemWindows(Rect), then there is no need to set this flag to true -- your implementation will be overriding the default implementation that checks this flag.

Parameters
fitSystemWindows boolean: If true, then the default implementation of fitSystemWindows(Rect) will be executed.

setOnHierarchyChangeListener

void setOnHierarchyChangeListener (ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener)

Register a callback to be invoked when a child is added to or removed from this view.

Parameters
onHierarchyChangeListener ViewGroup.OnHierarchyChangeListener: the callback to invoke on hierarchy change

setStatusBarBackground

void setStatusBarBackground (Drawable bg)

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

void setStatusBarBackgroundColor (int color)

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
color int: Color to use as a background drawable to draw behind the status bar in 0xAARRGGBB format.

setStatusBarBackgroundResource

void setStatusBarBackgroundResource (int resId)

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 int: Resource id of a background drawable to draw behind the status bar

setVisibility

void setVisibility (int visibility)

Set the enabled state of this view.

Parameters
visibility int: One of VISIBLE, INVISIBLE, or GONE.

Protected methods

checkLayoutParams

boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
boolean

drawChild

boolean drawChild (Canvas canvas, 
                View child, 
                long drawingTime)

Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.

Parameters
canvas Canvas: The canvas on which to draw the child
child View: Who to draw
drawingTime long: The time at which draw is occurring
Returns
boolean True if an invalidate() was issued

drawableStateChanged

void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

generateDefaultLayoutParams

CoordinatorLayout.LayoutParams generateDefaultLayoutParams ()

Returns a set of default layout parameters. These parameters are requested when the View passed to addView(View) has no layout parameters already set. If null is returned, an exception is thrown from addView.

Returns
CoordinatorLayout.LayoutParams a set of default layout parameters or null

generateLayoutParams

CoordinatorLayout.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(android.view.ViewGroup.LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.

Parameters
p ViewGroup.LayoutParams: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns
CoordinatorLayout.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

getSuggestedMinimumHeight

int getSuggestedMinimumHeight ()

Returns the suggested minimum height that the view should use. This returns the maximum of the view's minimum height and the background's minimum height (getMinimumHeight()).

When being used in onMeasure(int, int), the caller should still ensure the returned height is within the requirements of the parent.

Returns
int The suggested minimum height of the view.

getSuggestedMinimumWidth

int getSuggestedMinimumWidth ()

Returns the suggested minimum width that the view should use. This returns the maximum of the view's minimum width and the background's minimum width (getMinimumWidth()).

When being used in onMeasure(int, int), the caller should still ensure the returned width is within the requirements of the parent.

Returns
int The suggested minimum width of the view.

onLayout

void onLayout (boolean changed, 
                int l, 
                int t, 
                int r, 
                int b)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed boolean: This is a new size or position for this view
l int: Left position, relative to parent
t int: Top position, relative to parent
r int: Right position, relative to parent
b int: Bottom position, relative to parent

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

onRestoreInstanceState

void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.

verifyDrawable

boolean verifyDrawable (Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who Drawable: The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.