public class MotionLayout extends ConstraintLayout implements NestedScrollingParent3


A subclass of ConstraintLayout that supports animating between various states Added in 2.0

A MotionLayout is a subclass of ConstraintLayout which supports transitions between between various states (ConstraintSet) defined in MotionScenes.

Note:MotionLayout is available as a support library that you can use on Android systems starting with API level 14 (ICS).

MotionLayout links to and requires a MotionScene file. The file contains one top level tag "MotionScene"

LayoutDescription

Tags Description
<StateSet> Describes states supported by the system (optional)
<ConstraintSet> Describes a constraint set
<Transition> Describes a transition between two states or ConstraintSets
<ViewTransition> Describes a transition of a View within a states or ConstraintSets

Transition

Attributes Description
android:id The id of the Transition
constraintSetStart ConstraintSet to be used as the start constraints or a layout file to get the constraint from
constraintSetEnd ConstraintSet to be used as the end constraints or a layout file to get the constraint from
motionInterpolator The ability to set an overall interpolation (easeInOut, linear, etc.)
duration Length of time to take to perform the transition
staggered Overrides the Manhattan distance from the top most view in the list of views.
  • For any view of stagger value S(Vi)
  • With the transition stagger value of TS (from 0.0 - 1.0)
  • The duration of the animation is duration
  • The views animation duration DS = duration * (1 -TS)
  • Call the stagger fraction SFi = (S(Vi) - S(V0)) / (S(Vn) - S(V0))
  • The view starts animating at: (duration-DS) * SFi
pathMotionArc The path will move in arc (quarter ellipses) key words {startVertical | startHorizontal | flip | none }
autoTransition automatically transition from one state to another. key words {none, jumpToStart, jumpToEnd, animateToStart, animateToEnd}
transitionFlags flags that adjust the behaviour of Transitions. supports {none, beginOnFirstDraw} begin on first draw forces the transition's clock to start when it is first displayed not when the begin is called
layoutDuringTransition Configures MotionLayout on how to react to requestLayout calls during transitions. Allowed values are {ignoreRequest, honorRequest}
<OnSwipe> Adds support for touch handling (optional)
<OnClick> Adds support for triggering transition (optional)
<KeyFrameSet> Describes a set of Key object which modify the animation between constraint sets.
  • A transition is typically defined by specifying its start and end ConstraintSets. You also have the possibility to not specify them, in which case such transition will become a Default transition. That Default transition will be applied between any state change that isn't explicitly covered by a transition.
  • The starting state of the MotionLayout is defined to be the constraintSetStart of the first transition.
  • If no transition is specified (or only a default Transition) the MotionLayout tag must contain a app:currentState to define the starting state of the MotionLayout

ViewTransition

Attributes Description
android:id The id of the ViewTransition
viewTransitionMode currentState, allStates, noState transition affect the state of the view in the current constraintSet or all ConstraintSets or non if noState the ViewTransitions are run asynchronous
onStateTransition actionDown or actionUp run transition if on touch down or up if view matches motionTarget
motionInterpolator The ability to set an overall interpolation key words {easeInOut, linear, etc.}
duration Length of time to take to perform the ViewTransition
pathMotionArc The path will move in arc (quarter ellipses) key words {startVertical | startHorizontal | flip | none }
motionTarget Apply ViewTransition matching this string or id.
setsTag set this tag at end of transition
clearsTag clears this tag at end of transition
ifTagSet run transition if this tag is set on view
ifTagNotSet run transition if this tag is not set on view/td>
<OnSwipe> Adds support for touch handling (optional)
<OnClick> Adds support for triggering transition (optional)
<KeyFrameSet> Describes a set of Key object which modify the animation between constraint sets.
  • A Transition is typically defined by specifying its start and end ConstraintSets. You also have the possibility to not specify them, in which case such transition will become a Default transition. That Default transition will be applied between any state change that isn't explicitly covered by a transition.
  • The starting state of the MotionLayout is defined to be the constraintSetStart of the first transition.
  • If no transition is specified (or only a default Transition) the MotionLayout tag must contain a app:currentState to define the starting state of the MotionLayout

OnSwipe (optional)

Attributes Description
touchAnchorId Have the drag act as if it is moving the "touchAnchorSide" of this object
touchRegionId Limits the region that the touch can be start in to the bounds of this view (even if the view is invisible)
touchAnchorSide The side of the object to move with {top|left|right|bottom}
maxVelocity limit the maximum velocity (in progress/sec) of the animation will on touch up. Default 4
dragDirection which side to swipe from {dragUp|dragDown|dragLeft|dragRight}
maxAcceleration how quickly the animation will accelerate (progress/sec/sec) and decelerate on touch up. Default 1.2
dragScale scale factor to adjust the swipe by. (e.g. 0.5 would require you to move 2x as much)
dragThreshold How much to drag before swipe gesture runs. Important for mult-direction swipe. Default is 10. 1 is very sensitive.
moveWhenScrollAtTop If the swipe is scrolling and View (such as RecyclerView or NestedScrollView) do scroll and transition happen at the same time
onTouchUp Support for various swipe modes autoComplete,autoCompleteToStart,autoCompleteToEnd,stop,decelerate,decelerateAndComplete

OnClick (optional)

Attributes Description
motionTarget What view triggers Transition.
clickAction Direction for buttons to move the animation. Or (|) combination of: toggle, transitionToEnd, transitionToStart, jumpToEnd, jumpToStart

StateSet

defaultState The constraint set or layout to use
<State> The side of the object to move

State

android:id Id of the State
constraints Id of the ConstraintSet or the Layout file
<Variant> a different constraintSet/layout to choose if the with or height matches

Variant

region_widthLessThan Match if width less than
region_widthMoreThan Match if width more than
region_heightLessThan Match if height less than
region_heightMoreThan Match if height more than
constraints Id of the ConstraintSet or layout

ConstraintSet

android:id The id of the ConstraintSet
deriveConstraintsFrom The id of another constraintSet which defines the constraints not define in this set. If not specified the layout defines the undefined constraints.
<Constraint> A ConstraintLayout Constraints + other attributes associated with a view

Constraint

Constraint supports two forms:

1: All of ConstraintLayout + the ones listed below + <CustomAttribute> .

Or

2: Combination of tags: <Layout> <PropertySet> <Transform> <Motion> <CustomAttribute> . The advantage of using these is that if not present the attributes are taken from the base layout file. This saves from replicating all the layout tags if only a Motion tag is needed. If is used then all layout attributes in the base are ignored.

android:id Id of the View
[ConstraintLayout attributes] Any attribute that is part of ConstraintLayout layout is allowed
[Standard View attributes] A collection of view attributes supported by the system (see below)
transitionEasing define an easing curve to be used when animating from this point (e.g. curve(1.0,0,0,1.0)) or key words {standard | accelerate | decelerate | linear}
pathMotionArc the path will move in arc (quarter ellipses) or key words {startVertical | startHorizontal | none }
transitionPathRotate (float) rotate object relative to path taken
drawPath draw the path the layout will animate animate
progress call method setProgress(float) on this view (used to talk to nested ConstraintLayouts etc.)
<CustomAttribute> call a set"name" method via reflection
<Layout> Attributes for the ConstraintLayout e.g. layout_constraintTop_toTopOf
<PropertySet> currently only visibility, alpha, motionProgress,layout_constraintTag.
<Transform> All the view transform API such as android:rotation.
<Motion> Motion Layout control commands such as transitionEasing and pathMotionArc

Layout

[ConstraintLayout attributes] Also see ConstraintLayout.LayoutParams for attributes

PropertySet

visibility set the Visibility of the view. One of Visible, invisible or gone
alpha setAlpha value
motionProgress using reflection call setProgress
layout_constraintTag a tagging string to identify the type of object

Transform

android:elevation base z depth of the view.
android:rotation rotation of the view, in degrees.
android:rotationX rotation of the view around the x axis, in degrees.
android:rotationY rotation of the view around the y axis, in degrees.
android:scaleX scale of the view in the x direction
android:scaleY scale of the view in the y direction.
android:translationX translation in x of the view. This value is added post-layout to the left property of the view, which is set by its layout.
android:translationY translation in y of the view. This value is added post-layout to th e top property of the view, which is set by its layout
android:translationZ translation in z of the view. This value is added to its elevation.

Motion

transitionEasing Defines an acceleration curve.
pathMotionArc Says the object should move in a quarter ellipse unless the motion is vertical or horizontal
motionPathRotate set the rotation to the path of the object + this angle.
drawPath Debugging utility to draw the motion of the path

CustomAttribute

attributeName The name of the attribute. Case sensitive. ( MyAttr will look for method setMyAttr(...)
customColorValue The value is a color looking setMyAttr(int )
customIntegerValue The value is an integer looking setMyAttr(int )
customFloatValue The value is a float looking setMyAttr(float )
customStringValue The value is a String looking setMyAttr(String )
customDimension The value is a dimension looking setMyAttr(float )
customBoolean The value is true or false looking setMyAttr(boolean )

KeyFrameSet

This is the container for a collection of Key objects (such as KeyPosition) which provide information about how the views should move

<KeyPosition> Controls the layout position during animation
<KeyAttribute> Controls the post layout properties during animation
<KeyCycle> Controls oscillations with respect to position of post layout properties during animation
<KeyTimeCycle> Controls oscillations with respect to time of post layout properties during animation
<KeyTrigger> trigger callbacks into code at fixed point during the animation

KeyPosition

motionTarget Id of the View or a regular expression to match layout_ConstraintTag
framePosition The point along the interpolation 0 = start 100 = end
transitionEasing define an easing curve to be used when animating from this point (e.g. curve(1.0,0,0, 1.0)) or key words {standard | accelerate | decelerate | linear }
pathMotionArc The path will move in arc (quarter ellipses) key words {startVertical | startHorizontal | flip | none }
keyPositionType how this keyframe's deviation for linear path is calculated {deltaRelative | pathRelative|parentRelative}
percentX (float) percent distance from start to end along X axis (deltaRelative) or along the path in pathRelative
percentY (float) Percent distance from start to end along Y axis (deltaRelative) or perpendicular to path in pathRelative
percentWidth (float) Percent of change in the width. Note if the width does not change this has no effect.This overrides sizePercent.
percentHeight (float) Percent of change in the width. Note if the width does not change this has no effect.This overrides sizePercent.
curveFit path is traced
drawPath Draw the path of the objects layout takes useful for debugging
sizePercent If the view changes size this controls how growth of the size. (for fixed size objects use KeyAttributes scaleX/X)
curveFit selects a path based on straight lines or a path based on a monotonic spline {linear|spline}

KeyAttribute

motionTarget Id of the View or a regular expression to match layout_ConstraintTag
framePosition The point along the interpolation 0 = start 100 = end
curveFit selects a path based on straight lines or a path based on a monotonic spline {linear|spline}
transitionEasing Define an easing curve to be used when animating from this point (e.g. curve(1.0,0,0, 1.0)) or key words {standard | accelerate | decelerate | linear }
transitionPathRotate (float) rotate object relative to path taken
drawPath draw the path the layout will animate animate
motionProgress call method setProgress(float) on this view (used to talk to nested ConstraintLayouts etc.)
[standard view attributes](except visibility) A collection of post layout view attributes see below
<CustomAttribute> call a set"name" method via reflection

CustomAttribute

attributeName The name of the attribute. Case sensitive. ( MyAttr will look for method setMyAttr(...)
customColorValue The value is a color looking setMyAttr(int )
customIntegerValue The value is an integer looking setMyAttr(int )
customFloatValue The value is a float looking setMyAttr(float )
customStringValue The value is a String looking setMyAttr(String )
customDimension The value is a dimension looking setMyAttr(float )
customBoolean The value is true or false looking setMyAttr(boolean )

KeyCycle

motionTarget Id of the View or a regular expression to match layout_ConstraintTag
framePosition The point along the interpolation 0 = start 100 = end
[Standard View attributes] A collection of view attributes supported by the system (see below)
waveShape The shape of the wave to generate {sin|square|triangle|sawtooth|reverseSawtooth|cos|bounce}
wavePeriod The number of cycles to loop near this region
waveOffset offset value added to the attribute
transitionPathRotate Cycles applied to rotation relative to the path the view is travelling
progress call method setProgress(float) on this view (used to talk to nested ConstraintLayouts etc.)
<CustomAttribute> call a set"name" method via reflection (limited to floats)

CustomAttribute

attributeName The name of the attribute. Case sensitive. ( MyAttr will look for method setMyAttr(...)
customFloatValue The value is a float looking setMyAttr(float )

KeyTimeCycle

motionTarget Id of the View or a regular expression to match layout_ConstraintTag
framePosition The point along the interpolation 0 = start 100 = end
[Standard View attributes] A collection of view attributes supported by the system (see below)
waveShape The shape of the wave to generate {sin|square|triangle|sawtooth|reverseSawtooth|cos|bounce}
wavePeriod The number of cycles per second
waveOffset offset value added to the attribute
transitionPathRotate Cycles applied to rotation relative to the path the view is travelling
progress call method setProgress(float) on this view (used to talk to nested ConstraintLayouts etc.)
<CustomAttribute> call a set"name" method via reflection (limited to floats)

CustomAttribute

attributeName The name of the attribute. Case sensitive. ( MyAttr will look for method setMyAttr(...)
customFloatValue The value is a float looking setMyAttr(float )

KeyTrigger

motionTarget Id of the View or a regular expression to match layout_ConstraintTag
framePosition The point along the interpolation 0 = start 100 = end
onCross (method name) on crossing this position call this methods on the t arget
onPositiveCross (method name) on forward crossing of the framePosition call this methods on the target
onNegativeCross/td> (method name) backward crossing of the framePosition call this methods on the target
viewTransitionOnCross (ViewTransition Id) start a NoState view transition on crossing or hitting target
viewTransitionOnPositiveCross (ViewTransition Id) start a NoState view transition forward crossing of the framePosition or entering target
viewTransitionOnNegativeCross/td> (ViewTransition Id) start a NoState view transition backward crossing of the framePosition or leaving target
triggerSlack (float) do not call trigger again if the framePosition has not moved this fraction away from the trigger point
triggerId (id) call the TransitionListener with this trigger id
motion_postLayoutCollision Define motion pre or post layout. Post layout is more expensive but captures KeyAttributes or KeyCycle motions.
motion_triggerOnCollision (id) Trigger if the motionTarget collides with the other motionTarget

Standard attributes

android:visibility Android view attribute that
android:alpha Android view attribute that
android:elevation base z depth of the view.
android:rotation rotation of the view, in degrees.
android:rotationX rotation of the view around the x axis, in degrees.
android:rotationY rotation of the view around the y axis, in degrees.
android:scaleX scale of the view in the x direction.
android:scaleY scale of the view in the y direction.
android:translationX translation in x of the view.
android:translationY translation in y of the view.
android:translationZ translation in z of the view.

Summary

Nested types

protected interface MotionLayout.MotionTracker

Subclasses can override to build test frameworks

Listener for monitoring events about TransitionLayout.

Constants

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Public fields

static boolean

Protected fields

boolean

Public constructors

MotionLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

void

adds a listener to be notified of drawer events.

boolean
applyViewTransition(
    int viewTransitionId,
    MotionController motionController
)

Apply the view transitions keyFrames to the MotionController.

ConstraintSet

Creates a ConstraintSet based on an existing constraintSet.

void
enableTransition(int transitionID, boolean enable)

Disable the transition based on transitionID

void
enableViewTransition(int viewTransitionId, boolean enable)

Enable a ViewTransition ID.

void
fireTrigger(int triggerId, boolean positive, float progress)

This causes the callback onTransitionTrigger to be called

ConstraintSet

Get the ConstraintSet associated with an id This returns a link to the constraintSet But in most cases can be used. createConstraintSet makes a copy which is more expensive.

@IdRes int[]

Get the id's of all constraintSets used by MotionLayout

int

Return the current state id

ArrayList<MotionScene.Transition>

Get all Transitions known to the system.

DesignTool
int

Gets the state you are currently transition to.

int[]

Get the id's of all constraintSets with the matching types

float

Get current position during an animation.

MotionScene

Get the motion scene of the layout.

int

Gets the state you are currently transitioning from.

float

Gets the position you are animating to typically 0 or 1.

MotionScene.Transition
getTransition(int id)

This returns the internal Transition Structure

Bundle
long

Gets the time of the currently set animation.

float

Returns the last velocity used in the transition

void
getViewVelocity(
    View view,
    float posOnViewX,
    float posOnViewY,
    float[] returnVelocity,
    int type
)

Returns the last layout velocity used in the transition

boolean

Is initial state changes are applied during onAttachedToWindow or after.

boolean
boolean

Determines whether MotionLayout's touch &click handling are enabled.

boolean
isViewTransitionEnabled(int viewTransitionId)

Is transition id enabled or disabled

void
jumpToState(int id)

This jumps to a state It will be at that state after one repaint cycle If the current transition contains that state.

void
loadLayoutDescription(int motionScene)

This overrides ConstraintLayout and only accepts a MotionScene.

boolean

Intercepts the touch event to correctly handle touch region id handover

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

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

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

React to a nested scroll in progress.

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

React to a nested scroll in progress.

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

React to the successful claiming of a nested scroll operation.

void
onRtlPropertiesChanged(int layoutDirection)
boolean
onStartNestedScroll(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

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

void
onStopNestedScroll(@NonNull View target, int type)

React to a nested scroll operation ending.

boolean
void
void
void

This method is deprecated.

Please call rebuildScene() instead.

void

rebuild the motion Layouts

boolean

adds a listener to be notified of drawer events.

void
void
rotateTo(int id, int duration)

Rotate the layout based on the angle to a ConstraintSet

void

on completing the current transition, transition to this state.

void
setDebugMode(int debugMode)

Display the debugging information such as paths information

void

Initial state changes are applied during onAttachedToWindow unless this is set to true.

void
setInteractionEnabled(boolean enabled)

Enables (or disables) MotionLayout's onClick and onSwipe handling.

void

Set the transition position between 0 an 1

void
setOnHide(float progress)

Notify OnHide motion helpers

void
setOnShow(float progress)

Notify OnShow motion helpers

void
setProgress(float pos)

Set the transition position between 0 an 1

void
setProgress(float pos, float velocity)

Set the transition position between 0 an 1

void

Sets a motion scene to the layout.

void
setState(int id, int screenWidth, int screenHeight)

Set the State of the Constraint layout.

void
setTransition(int transitionId)

Set a transition explicitly to a Transition that has an ID The transition must have been named with android:id=...

void
setTransition(int beginId, int endId)

Set a transition explicitly between two constraint sets

void
setTransitionDuration(int milliseconds)

Change the current Transition duration.

void

Set a listener to be notified of drawer events.

void

Set the transition state as a bundle

String
void
touchAnimateTo(int touchUpMode, float position, float currentVelocity)
void
touchSpringTo(float position, float currentVelocity)

Allows you to use trigger spring motion touch behaviour.

void

Animate to the ending position of the current transition.

void

Animate to the ending position of the current transition.

void

Animate to the starting position of the current transition.

void

Animate to the starting position of the current transition.

void

Animate to the state defined by the id.

void
transitionToState(int id, int duration)

Animate to the state defined by the id.

void
transitionToState(int id, int screenWidth, int screenHeight)

Animate to the state defined by the id.

void
transitionToState(
    int id,
    int screenWidth,
    int screenHeight,
    int duration
)

Animate to the state defined by the id.

void

Not sure we want this

void
updateState(int stateId, ConstraintSet set)

update a ConstraintSet under the id.

void
updateStateAnimate(int stateId, ConstraintSet set, int duration)

Update a ConstraintSet but animate the change.

void
viewTransition(int viewTransitionId, View[] view)

Execute a ViewTransition.

Protected methods

void

Used to draw debugging graphics and to do post layout changes

void

This causes the callback TransitionCompleted to be called

long

Subclasses can override to define testClasses

MotionLayout.MotionTracker

Subclasses can override to build test frameworks

void
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void

block ConstraintLayout from handling layout description

void

Inherited Constants

From androidx.constraintlayout.widget.ConstraintLayout
static final int
static final String
VERSION = "ConstraintLayout-2.2.0-alpha04"
From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From androidx.constraintlayout.widget.ConstraintLayout
void

a ValueModify to the ConstraintLayout.

void
applyConstraintsFromLayoutParams(
    boolean isInEditMode,
    View child,
    ConstraintWidget widget,
    ConstraintLayout.LayoutParams layoutParams,
    SparseArray<ConstraintWidget> idToWidget
)
boolean
boolean
dynamicUpdateConstraints(int widthMeasureSpec, int heightMeasureSpec)

This can be overridden to change the way Modifiers are used.

void
void
ConstraintLayout.LayoutParams
ConstraintLayout.LayoutParams
ViewGroup.LayoutParams
Object
getDesignInformation(int type, Object value)
int

The maximum height of this view.

int
int

The minimum height of this view.

int

The minimum width of this view.

int

Return the current optimization level for the layout resolution

String

Returns a JSON5 string useful for debugging the constraints actually applied.

static SharedValues

Returns the SharedValues instance, creating it if it doesn't exist.

View
getViewById(int id)
final ConstraintWidget
boolean
void
resolveMeasuredDimension(
    int widthMeasureSpec,
    int heightMeasureSpec,
    int measuredWidth,
    int measuredHeight,
    boolean isWidthMeasuredTooSmall,
    boolean isHeightMeasuredTooSmall
)

Handles calling setMeasuredDimension()

void
resolveSystem(
    ConstraintWidgetContainer layout,
    int optimizationLevel,
    int widthMeasureSpec,
    int heightMeasureSpec
)

Handles measuring a layout

void

Sets a ConstraintSet object to manage constraints.

void
setDesignInformation(int type, Object value1, Object value2)
void
setId(int id)
void
setMaxHeight(int value)

Set the max height for this view

void
setMaxWidth(int value)

Set the max width for this view

void
setMinHeight(int value)

Set the min height for this view

void
setMinWidth(int value)

Set the min width for this view

void
setOnConstraintsChanged(
    ConstraintsChangedListener constraintsChangedListener
)

Notify of constraints changed

void

Set the optimization for the layout resolution.

void
setSelfDimensionBehaviour(
    ConstraintWidgetContainer layout,
    int widthMode,
    int widthSize,
    int heightMode,
    int heightSize
)
boolean
From androidx.core.view.NestedScrollingParent
abstract int

Return the current axes of nested scrolling for this NestedScrollingParent.

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

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

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

React to a nested scroll in progress.

abstract void
onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes)

React to the successful claiming of a nested scroll operation.

abstract boolean
onStartNestedScroll(@NonNull View child, @NonNull View target, int axes)

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

abstract void

React to a nested scroll operation ending.

From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
boolean
boolean
void
void
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
onDraw(Canvas canvas)
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
void
Parcelable
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, Bundle arguments)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
void
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setEnabled(boolean enabled)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
boolean
void
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean
From android.view.ViewGroup
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction, int focusableMode)
void
boolean
void
void
addView(View child)
boolean
addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
void
attachLayoutAnimationParameters(
    View child,
    ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
void
boolean
boolean
void
void
childHasTransientStateChanged(
    View child,
    boolean childHasTransientState
)
void
void
void
void
void
debug(int depth)
void
void
void
detachViewsFromParent(int start, int count)
WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
void
boolean
boolean
boolean
boolean
boolean
boolean
void
dispatchPointerCaptureChanged(boolean hasCapture)
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

void
boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
boolean
drawChild(Canvas canvas, View child, long drawingTime)
void
void
View
OnBackInvokedDispatcher
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence text,
    int flags
)
View
focusSearch(View focused, int direction)
void
boolean
ViewGroup.LayoutParams
ViewGroup.LayoutParams
CharSequence
View
getChildAt(int index)
int
int
getChildDrawingOrder(int childCount, int drawingPosition)
static int
getChildMeasureSpec(int spec, int padding, int childDimension)
boolean
boolean
getChildVisibleRect(View child, Rect r, Point offset)
boolean
boolean
int
View
LayoutAnimationController
Animation.AnimationListener
int
LayoutTransition
int
ViewGroupOverlay
int

This method is deprecated.

boolean
boolean
boolean
int
final void
invalidateChild(View child, Rect dirty)

This method is deprecated.

ViewParent
invalidateChildInParent(int[] location, Rect dirty)

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

boolean
boolean

This method is deprecated.

boolean
boolean
boolean
void
final void
layout(int l, int t, int r, int b)
void
measureChild(
    View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
void
notifySubtreeAccessibilityStateChanged(
    View child,
    View source,
    int changeType
)
final void
final void
int[]
onCreateDrawableState(int extraSpace)
void
void
boolean
abstract void
onLayout(boolean p, int p1, int p2, int p3, int p4)
boolean
onNestedPrePerformAccessibilityAction(
    View target,
    int action,
    Bundle args
)
void
onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void
onNestedScroll(
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)
void
onNestedScrollAccepted(View child, View target, int axes)
boolean
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
boolean
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
boolean
onStartNestedScroll(View child, View target, int nestedScrollAxes)
void
void
void
void
void
void
void
removeDetachedView(View child, boolean animate)
void
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
requestChildFocus(View child, View focused)
boolean
requestChildRectangleOnScreen(
    View child,
    Rect rectangle,
    boolean immediate
)
void
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
boolean
requestFocus(int direction, Rect previouslyFocusedRect)
boolean
void
boolean
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated.

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void

This method is deprecated.

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated.

void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
void
boolean
boolean
ActionMode
startActionModeForChild(
    View originalView,
    ActionMode.Callback callback
)
void
void
void
suppressLayout(boolean suppress)
void

Constants

DEBUG_SHOW_NONE

Added in 2.2.0-rc01
public static final int DEBUG_SHOW_NONE = 0

DEBUG_SHOW_PATH

Added in 2.2.0-rc01
public static final int DEBUG_SHOW_PATH = 2

DEBUG_SHOW_PROGRESS

Added in 2.2.0-rc01
public static final int DEBUG_SHOW_PROGRESS = 1

TOUCH_UP_COMPLETE

Added in 2.2.0-rc01
public static final int TOUCH_UP_COMPLETE = 0

TOUCH_UP_COMPLETE_TO_END

Added in 2.2.0-rc01
public static final int TOUCH_UP_COMPLETE_TO_END = 2

TOUCH_UP_COMPLETE_TO_START

Added in 2.2.0-rc01
public static final int TOUCH_UP_COMPLETE_TO_START = 1

TOUCH_UP_DECELERATE

Added in 2.2.0-rc01
public static final int TOUCH_UP_DECELERATE = 4

TOUCH_UP_DECELERATE_AND_COMPLETE

Added in 2.2.0-rc01
public static final int TOUCH_UP_DECELERATE_AND_COMPLETE = 5

TOUCH_UP_NEVER_TO_END

Added in 2.2.0-rc01
public static final int TOUCH_UP_NEVER_TO_END = 7

TOUCH_UP_NEVER_TO_START

Added in 2.2.0-rc01
public static final int TOUCH_UP_NEVER_TO_START = 6

TOUCH_UP_STOP

Added in 2.2.0-rc01
public static final int TOUCH_UP_STOP = 3

VELOCITY_LAYOUT

Added in 2.2.0-rc01
public static final int VELOCITY_LAYOUT = 1

VELOCITY_POST_LAYOUT

Added in 2.2.0-rc01
public static final int VELOCITY_POST_LAYOUT = 0

VELOCITY_STATIC_LAYOUT

Added in 2.2.0-rc01
public static final int VELOCITY_STATIC_LAYOUT = 3

VELOCITY_STATIC_POST_LAYOUT

Added in 2.2.0-rc01
public static final int VELOCITY_STATIC_POST_LAYOUT = 2

Public fields

IS_IN_EDIT_MODE

Added in 2.2.0-rc01
public static boolean IS_IN_EDIT_MODE

Protected fields

mMeasureDuringTransition

Added in 2.2.0-rc01
protected boolean mMeasureDuringTransition

Public constructors

MotionLayout

Added in 2.2.0-rc01
public MotionLayout(@NonNull Context context)

MotionLayout

Added in 2.2.0-rc01
public MotionLayout(@NonNull Context context, @Nullable AttributeSet attrs)

MotionLayout

Added in 2.2.0-rc01
public MotionLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

addTransitionListener

Added in 2.2.0-rc01
public void addTransitionListener(MotionLayout.TransitionListener listener)

adds a listener to be notified of drawer events.

Parameters
MotionLayout.TransitionListener listener

Listener to notify when drawer events occur

applyViewTransition

Added in 2.2.0-rc01
public boolean applyViewTransition(
    int viewTransitionId,
    MotionController motionController
)

Apply the view transitions keyFrames to the MotionController. Note ConstraintOverride is not used

Parameters
int viewTransitionId

the id of the view transition

MotionController motionController

the MotionController to apply the keyframes to

Returns
boolean

true if it found and applied the viewTransition false otherwise

cloneConstraintSet

Added in 2.2.0-rc01
public ConstraintSet cloneConstraintSet(int id)

Creates a ConstraintSet based on an existing constraintSet. This makes a copy of the ConstraintSet.

Parameters
int id

The ide of the ConstraintSet

Returns
ConstraintSet

the ConstraintSet

enableTransition

Added in 2.2.0-rc01
public void enableTransition(int transitionID, boolean enable)

Disable the transition based on transitionID

Parameters
int transitionID
boolean enable

enableViewTransition

Added in 2.2.0-rc01
public void enableViewTransition(int viewTransitionId, boolean enable)

Enable a ViewTransition ID.

Parameters
int viewTransitionId

id of ViewTransition

boolean enable

If false view transition cannot be executed.

fireTrigger

Added in 2.2.0-rc01
public void fireTrigger(int triggerId, boolean positive, float progress)

This causes the callback onTransitionTrigger to be called

Parameters
int triggerId

The id set set with triggerID

boolean positive

for positive transition edge

float progress

the current progress

getConstraintSet

Added in 2.2.0-rc01
public ConstraintSet getConstraintSet(int id)

Get the ConstraintSet associated with an id This returns a link to the constraintSet But in most cases can be used. createConstraintSet makes a copy which is more expensive.

Parameters
int id

of the constraintSet

Returns
ConstraintSet

ConstraintSet of MotionLayout

getConstraintSetIds

Added in 2.2.0-rc01
public @IdRes int[] getConstraintSetIds()

Get the id's of all constraintSets used by MotionLayout

Returns
@IdRes int[]

getCurrentState

Added in 2.2.0-rc01
public int getCurrentState()

Return the current state id

Returns
int

current state id

getDefinedTransitions

Added in 2.2.0-rc01
public ArrayList<MotionScene.TransitiongetDefinedTransitions()

Get all Transitions known to the system.

getDesignTool

Added in 2.2.0-rc01
public DesignTool getDesignTool()

getEndState

Added in 2.2.0-rc01
public int getEndState()

Gets the state you are currently transition to.

Returns
int

The State you are transitioning to.

getMatchingConstraintSetIds

public int[] getMatchingConstraintSetIds(String[] types)

Get the id's of all constraintSets with the matching types

Returns
int[]

getProgress

Added in 2.2.0-rc01
public float getProgress()

Get current position during an animation.

Returns
float

current position from 0.0 to 1.0 inclusive

getScene

Added in 2.2.0-rc01
public MotionScene getScene()

Get the motion scene of the layout. Warning! This gives you direct access to the internal state of the MotionLayout making it easy corrupt the state.

Returns
MotionScene

the motion scene

getStartState

Added in 2.2.0-rc01
public int getStartState()

Gets the state you are currently transitioning from. If you are transitioning from an unknown state returns -1

Returns
int

State you are transitioning from.

getTargetPosition

Added in 2.2.0-rc01
public float getTargetPosition()

Gets the position you are animating to typically 0 or 1. This is useful during animation after touch up

Returns
float

The target position you are moving to

getTransition

Added in 2.2.0-rc01
public MotionScene.Transition getTransition(int id)

This returns the internal Transition Structure

Parameters
int id

getTransitionState

Added in 2.2.0-rc01
public Bundle getTransitionState()
Returns
Bundle

bundle containing start and end state

getTransitionTimeMs

Added in 2.2.0-rc01
public long getTransitionTimeMs()

Gets the time of the currently set animation.

Returns
long

time in Milliseconds

getVelocity

Added in 2.2.0-rc01
public float getVelocity()

Returns the last velocity used in the transition

Returns
float

getViewVelocity

Added in 2.2.0-rc01
public void getViewVelocity(
    View view,
    float posOnViewX,
    float posOnViewY,
    float[] returnVelocity,
    int type
)

Returns the last layout velocity used in the transition

Parameters
View view

The view

float posOnViewX

The x position on the view

float posOnViewY

The y position on the view

float[] returnVelocity

The velocity

int type

Velocity returned 0 = post layout, 1 = layout, 2 = static postlayout

isDelayedApplicationOfInitialState

Added in 2.2.0-rc01
public boolean isDelayedApplicationOfInitialState()

Is initial state changes are applied during onAttachedToWindow or after.

Returns
boolean

isInRotation

Added in 2.2.0-rc01
public boolean isInRotation()

isInteractionEnabled

Added in 2.2.0-rc01
public boolean isInteractionEnabled()

Determines whether MotionLayout's touch &click handling are enabled. An interaction enabled MotionLayout can respond to user input and initiate and control. MotionLayout interactions are enabled initially by default. MotionLayout touch &click handling may be enabled or disabled by calling its setInteractionEnabled method.

Returns
boolean

true if MotionLayout's touch &click is enabled, false otherwise

isViewTransitionEnabled

Added in 2.2.0-rc01
public boolean isViewTransitionEnabled(int viewTransitionId)

Is transition id enabled or disabled

Parameters
int viewTransitionId

the ide of the transition

Returns
boolean

true if enabled

jumpToState

Added in 2.2.0-rc01
public void jumpToState(int id)

This jumps to a state It will be at that state after one repaint cycle If the current transition contains that state. It setsProgress 0 or 1 to that state. If not in the current transition itsl

Parameters
int id

state to set

loadLayoutDescription

public void loadLayoutDescription(int motionScene)

This overrides ConstraintLayout and only accepts a MotionScene.

Parameters
int motionScene

The resource id, or 0 to reset the MotionScene.

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent event)

Intercepts the touch event to correctly handle touch region id handover

Parameters
MotionEvent event
Returns
boolean

onNestedFling

public boolean onNestedFling(
    @NonNull View target,
    float velocityX,
    float velocityY,
    boolean consumed
)

onNestedPreFling

public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY)

onNestedPreScroll

Added in 2.2.0-rc01
public void onNestedPreScroll(
    @NonNull View target,
    int dx,
    int dy,
    @NonNull int[] consumed,
    int type
)

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
@NonNull View target

View that initiated the nested scroll

int dx

Horizontal scroll distance in pixels

int dy

Vertical scroll distance in pixels

@NonNull int[] consumed

Output. The horizontal and vertical scroll distance consumed by this parent

int type

the type of input which cause this scroll event

onNestedScroll

Added in 2.2.0-rc01
public void onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type
)

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
@NonNull View target

The descendent view controlling the nested scroll

int dxConsumed

Horizontal scroll distance in pixels already consumed by target

int dyConsumed

Vertical scroll distance in pixels already consumed by target

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by target

int dyUnconsumed

Vertical scroll distance in pixels not consumed by target

int type

the type of input which cause this scroll event

onNestedScroll

Added in 2.2.0-rc01
public void onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type,
    int[] consumed
)

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
@NonNull View target

The descendant view controlling the nested scroll

int dxConsumed

Horizontal scroll distance in pixels already consumed by target

int dyConsumed

Vertical scroll distance in pixels already consumed by target

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by target

int dyUnconsumed

Vertical scroll distance in pixels not consumed by target

int type

the type of input which cause this scroll event

int[] consumed

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

onNestedScrollAccepted

Added in 2.2.0-rc01
public void onNestedScrollAccepted(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

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
@NonNull View child

Direct child of this ViewParent containing target

@NonNull View target

View that initiated the nested scroll

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both

int type

the type of input which cause this scroll event

onRtlPropertiesChanged

public void onRtlPropertiesChanged(int layoutDirection)

onStartNestedScroll

Added in 2.2.0-rc01
public boolean onStartNestedScroll(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

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
@NonNull View child

Direct child of this ViewParent containing target

@NonNull View target

View that initiated the nested scroll

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both

int type

the type of input which cause this scroll event

Returns
boolean

true if this ViewParent accepts the nested scroll operation

onStopNestedScroll

Added in 2.2.0-rc01
public void onStopNestedScroll(@NonNull View target, int type)

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
@NonNull View target

View that initiated the nested scroll

int type

the type of input which cause this scroll event

onTouchEvent

public boolean onTouchEvent(MotionEvent event)

onViewAdded

public void onViewAdded(View view)

onViewRemoved

public void onViewRemoved(View view)

rebuildMotion

Added in 2.2.0-rc01
Deprecated in 2.2.0-rc01
public void rebuildMotion()

rebuild the motion Layouts

rebuildScene

Added in 2.2.0-rc01
public void rebuildScene()

rebuild the motion Layouts

removeTransitionListener

Added in 2.2.0-rc01
public boolean removeTransitionListener(MotionLayout.TransitionListener listener)

adds a listener to be notified of drawer events.

Parameters
MotionLayout.TransitionListener listener

Listener to notify when drawer events occur

Returns
boolean

true if it contained the specified listener

requestLayout

public void requestLayout()

rotateTo

Added in 2.2.0-rc01
public void rotateTo(int id, int duration)

Rotate the layout based on the angle to a ConstraintSet

Parameters
int id

constraintSet

int duration

time to take to rotate

scheduleTransitionTo

Added in 2.2.0-rc01
public void scheduleTransitionTo(int id)

on completing the current transition, transition to this state.

Parameters
int id

setDebugMode

Added in 2.2.0-rc01
public void setDebugMode(int debugMode)

Display the debugging information such as paths information

Parameters
int debugMode

integer representing various debug modes

setDelayedApplicationOfInitialState

Added in 2.2.0-rc01
public void setDelayedApplicationOfInitialState(boolean delayedApply)

Initial state changes are applied during onAttachedToWindow unless this is set to true.

Parameters
boolean delayedApply

setInteractionEnabled

Added in 2.2.0-rc01
public void setInteractionEnabled(boolean enabled)

Enables (or disables) MotionLayout's onClick and onSwipe handling.

Parameters
boolean enabled

If true, touch &click is enabled; otherwise it is disabled

setInterpolatedProgress

Added in 2.2.0-rc01
public void setInterpolatedProgress(float pos)

Set the transition position between 0 an 1

Parameters
float pos

setOnHide

Added in 2.2.0-rc01
public void setOnHide(float progress)

Notify OnHide motion helpers

Parameters
float progress

setOnShow

Added in 2.2.0-rc01
public void setOnShow(float progress)

Notify OnShow motion helpers

Parameters
float progress

setProgress

Added in 2.2.0-rc01
public void setProgress(float pos)

Set the transition position between 0 an 1

Parameters
float pos

the position in the transition from 0...1

setProgress

Added in 2.2.0-rc01
public void setProgress(float pos, float velocity)

Set the transition position between 0 an 1

Parameters
float pos
float velocity

setScene

Added in 2.2.0-rc01
public void setScene(MotionScene scene)

Sets a motion scene to the layout. Subsequent calls to it will override the previous scene.

setState

public void setState(int id, int screenWidth, int screenHeight)

Set the State of the Constraint layout. Causing it to load a particular ConstraintSet. for states with variants the variant with matching width and height constraintSet will be chosen

Parameters
int id

set the state width and height

int screenWidth
int screenHeight

setTransition

Added in 2.2.0-rc01
public void setTransition(int transitionId)

Set a transition explicitly to a Transition that has an ID The transition must have been named with android:id=...

Parameters
int transitionId

the id to set

setTransition

Added in 2.2.0-rc01
public void setTransition(int beginId, int endId)

Set a transition explicitly between two constraint sets

Parameters
int beginId

the id of the start constraint set

int endId

the id of the end constraint set

setTransitionDuration

Added in 2.2.0-rc01
public void setTransitionDuration(int milliseconds)

Change the current Transition duration.

Parameters
int milliseconds

duration for transition to complete

setTransitionListener

Added in 2.2.0-rc01
public void setTransitionListener(MotionLayout.TransitionListener listener)

Set a listener to be notified of drawer events.

Parameters
MotionLayout.TransitionListener listener

Listener to notify when drawer events occur

setTransitionState

Added in 2.2.0-rc01
public void setTransitionState(Bundle bundle)

Set the transition state as a bundle

toString

public String toString()

touchAnimateTo

Added in 2.2.0-rc01
public void touchAnimateTo(int touchUpMode, float position, float currentVelocity)
Parameters
int touchUpMode

behavior on touch up, can be either:

  • TOUCH_UP_COMPLETE (default) : will complete the transition, picking up automatically a correct velocity to do so
  • TOUCH_UP_STOP : will allow stopping mid-transition
  • TOUCH_UP_DECELERATE : will slowly decay, possibly past the transition (i.e. it will do a hard stop if unmanaged)
  • TOUCH_UP_DECELERATE_AND_COMPLETE : will automatically pick between TOUCH_UP_COMPLETE and TOUCH_UP_DECELERATE
, TOUCH_UP_STOP (will allow stopping
float position

animate to given position

float currentVelocity

touchSpringTo

Added in 2.2.0-rc01
public void touchSpringTo(float position, float currentVelocity)

Allows you to use trigger spring motion touch behaviour. You must have configured all the spring parameters in the Transition's OnSwipe

Parameters
float position

the position 0 - 1

float currentVelocity

the current velocity rate of change in position per second

transitionToEnd

Added in 2.2.0-rc01
public void transitionToEnd()

Animate to the ending position of the current transition. This will not work during on create as there is no transition Transitions are only set up during onAttach

transitionToEnd

Added in 2.2.0-rc01
public void transitionToEnd(Runnable onComplete)

Animate to the ending position of the current transition. This will not work during on create as there is no transition Transitions are only set up during onAttach

Parameters
Runnable onComplete

callback when task is done

transitionToStart

Added in 2.2.0-rc01
public void transitionToStart()

Animate to the starting position of the current transition. This will not work during on create as there is no transition Transitions are only set up during onAttach

transitionToStart

Added in 2.2.0-rc01
public void transitionToStart(Runnable onComplete)

Animate to the starting position of the current transition. This will not work during on create as there is no transition Transitions are only set up during onAttach

Parameters
Runnable onComplete

callback when task is done

transitionToState

Added in 2.2.0-rc01
public void transitionToState(int id)

Animate to the state defined by the id. The id is the id of the ConstraintSet or the id of the State.

Parameters
int id

the state to transition to

transitionToState

Added in 2.2.0-rc01
public void transitionToState(int id, int duration)

Animate to the state defined by the id. The id is the id of the ConstraintSet or the id of the State.

Parameters
int id

the state to transition to

int duration

time in ms. if 0 set by default or transition -1 by current

transitionToState

Added in 2.2.0-rc01
public void transitionToState(int id, int screenWidth, int screenHeight)

Animate to the state defined by the id. Width and height may be used in the picking of the id using this StateSet.

Parameters
int id

the state to transition

int screenWidth

the with of the motionLayout used to select the variant

int screenHeight

the height of the motionLayout used to select the variant

transitionToState

Added in 2.2.0-rc01
public void transitionToState(
    int id,
    int screenWidth,
    int screenHeight,
    int duration
)

Animate to the state defined by the id. Width and height may be used in the picking of the id using this StateSet.

Parameters
int id

the state to transition

int screenWidth

the with of the motionLayout used to select the variant

int screenHeight

the height of the motionLayout used to select the variant

int duration

time in ms. if 0 set by default or transition -1 by current

updateState

Added in 2.2.0-rc01
public void updateState()

Not sure we want this

updateState

Added in 2.2.0-rc01
public void updateState(int stateId, ConstraintSet set)

update a ConstraintSet under the id.

Parameters
int stateId

id of the ConstraintSet

ConstraintSet set

The constraintSet

updateStateAnimate

Added in 2.2.0-rc01
public void updateStateAnimate(int stateId, ConstraintSet set, int duration)

Update a ConstraintSet but animate the change.

Parameters
int stateId

id of the ConstraintSet

ConstraintSet set

The constraintSet

int duration

The length of time to perform the animation

viewTransition

public void viewTransition(int viewTransitionId, View[] view)

Execute a ViewTransition. Transition will execute if its conditions are met and it is enabled

Parameters
int viewTransitionId
View[] view

The views to apply to

Protected methods

dispatchDraw

protected void dispatchDraw(Canvas canvas)

Used to draw debugging graphics and to do post layout changes

Parameters
Canvas canvas

fireTransitionCompleted

Added in 2.2.0-rc01
protected void fireTransitionCompleted()

This causes the callback TransitionCompleted to be called

getNanoTime

Added in 2.2.0-rc01
protected long getNanoTime()

Subclasses can override to define testClasses

Returns
long

obtainVelocityTracker

Added in 2.2.0-rc01
protected MotionLayout.MotionTracker obtainVelocityTracker()

Subclasses can override to build test frameworks

onAttachedToWindow

protected void onAttachedToWindow()

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

parseLayoutDescription

protected void parseLayoutDescription(int id)

block ConstraintLayout from handling layout description

Parameters
int id

setTransition

Added in 2.2.0-rc01
protected void setTransition(MotionScene.Transition transition)