# MotionScene

Artifact: [androidx.constraintlayout:constraintlayout](https://developer.android.com/jetpack/androidx/releases/constraintlayout) [View Source](https://cs.android.com/search?q=file:androidx/constraintlayout/motion/widget/MotionScene.java+class:androidx.constraintlayout.motion.widget.MotionScene) Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

*** ** * ** ***


```
public class MotionScene
```

<br />

*** ** * ** ***

The information to transition between multiple ConstraintSets This Class is meant to be used from XML

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition` Transition defines the interaction from one state to another. |
| `public class https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition.TransitionOnClick implements https://developer.android.com/reference/android/view/View.OnClickListener.html` |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#LAYOUT_CALL_MEASURE() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#LAYOUT_HONOR_REQUEST() = 1` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#LAYOUT_IGNORE_REQUEST() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#UNSET() = -1` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#MotionScene(androidx.constraintlayout.motion.widget.MotionLayout)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout layout)` Create a motion scene. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#addOnClickListeners(androidx.constraintlayout.motion.widget.MotionLayout,int)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout motionLayout, int currentState)` Add all on click listeners for the current state |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#addTransition(androidx.constraintlayout.motion.widget.MotionScene.Transition)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition transition)` Add a transition to the motion scene. |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#applyViewTransition(int,androidx.constraintlayout.motion.widget.MotionController)( int viewTransitionId, https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController motionController )` Apply a view transition to the MotionController |
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#bestTransitionFor(int,float,float,android.view.MotionEvent)( int currentState, float dx, float dy, https://developer.android.com/reference/android/view/MotionEvent.html lastTouchDown )` Find the best transition for the motion |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#disableAutoTransition(boolean)(boolean disable)` this allow disabling autoTransitions to prevent design surface from being in undefined states |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#enableViewTransition(int,boolean)(int id, boolean enable)` Enable this viewTransition |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#gatPathMotionArc()()` The transition arc path mode |
| `https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintSet` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getConstraintSet(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html id)` Get the constraintSet given the id |
| `int[]` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getConstraintSetIds()()` Get the list of all Constraint Sets Know to the system |
| `https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition>` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getDefinedTransitions()()` Get list of Transitions know to the system |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getDuration()()` Get Duration of the current transition. |
| `https://developer.android.com/reference/android/view/animation/Interpolator.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getInterpolator()()` Get the interpolator define for the current Transition |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getKeyFrames(androidx.constraintlayout.motion.widget.MotionController)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController motionController)` provides the key frames \&CycleFrames to the motion view to |
| `int[]` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getMatchingStateLabels(java.lang.String...)(String[] types)` Get the id's of all constraintSets with the matching types |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getPathPercent(android.view.View,int)(https://developer.android.com/reference/android/view/View.html view, int position)` Get the path percent (Non functional currently) |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getStaggered()()` Get the staggered value of the current transition. |
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getTransitionById(int)(int id)` Find the transition based on the id |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition>` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#getTransitionsWithState(int)(int stateId)` Get all transitions that include this state |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#isViewTransitionEnabled(int)(int id)` Is this view transition enabled |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#lookUpConstraintId(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Used at design time |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#lookUpConstraintName(int)(int id)` used at design time |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#removeTransition(androidx.constraintlayout.motion.widget.MotionScene.Transition)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition transition)` Remove the transition with the matching id from the motion scene. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#setConstraintSet(int,androidx.constraintlayout.widget.ConstraintSet)(int id, https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintSet set)` Maps the Constraint set to the id. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#setDuration(int)(int duration)` Sets the duration of the current transition or the default if there is no current transition |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#setKeyframe(android.view.View,int,java.lang.String,java.lang.Object)(https://developer.android.com/reference/android/view/View.html view, int position, https://developer.android.com/reference/java/lang/String.html name, https://developer.android.com/reference/java/lang/Object.html value)` Set a keyFrame on the current Transition |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#setRtl(boolean)(boolean rtl)` Set Right to left |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#setTransition(androidx.constraintlayout.motion.widget.MotionScene.Transition)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition transition)` Set the transition to be the current transition of the motion scene. |
| `static https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#stripID(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Utility to strip the @id/ from an id |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#validateLayout(androidx.constraintlayout.motion.widget.MotionLayout)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout layout)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#viewTransition(int,android.view.View...)(int id, View[] view)` Apply the viewTransition on the list of views |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#onLayout(boolean,int,int,int,int)(boolean changed, int left, int top, int right, int bottom)` |

## Constants

### LAYOUT_CALL_MEASURE

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public static final int LAYOUT_CALL_MEASURE = 2
```

### LAYOUT_HONOR_REQUEST

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public static final int LAYOUT_HONOR_REQUEST = 1
```

### LAYOUT_IGNORE_REQUEST

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public static final int LAYOUT_IGNORE_REQUEST = 0
```

### UNSET

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public static final int UNSET = -1
```

## Public constructors

### MotionScene

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public MotionScene(MotionLayout layout)
```

Create a motion scene.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout layout` | Motion layout to which the scene will be set. |

## Public methods

### addOnClickListeners

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void addOnClickListeners(MotionLayout motionLayout, int currentState)
```

Add all on click listeners for the current state

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout motionLayout` |   |
| `int currentState` |   |

### addTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void addTransition(MotionScene.Transition transition)
```

Add a transition to the motion scene. If a transition with the same id already exists in the scene, the new transition will replace the existing one.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the transition does not have an id. |

### applyViewTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public boolean applyViewTransition(
    int viewTransitionId,
    MotionController motionController
)
```

Apply a view transition to the MotionController

| Parameters |
|---|---|
| `int viewTransitionId` | of viewTransition |
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController motionController` |   |

| Returns |
|---|---|
| `boolean` |   |

### bestTransitionFor

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public MotionScene.Transition bestTransitionFor(
    int currentState,
    float dx,
    float dy,
    MotionEvent lastTouchDown
)
```

Find the best transition for the motion

| Parameters |
|---|---|
| `int currentState` |   |
| `float dx` | drag delta x |
| `float dy` | drag delta y |
| `https://developer.android.com/reference/android/view/MotionEvent.html lastTouchDown` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition` |   |

### disableAutoTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void disableAutoTransition(boolean disable)
```

this allow disabling autoTransitions to prevent design surface from being in undefined states

| Parameters |
|---|---|
| `boolean disable` |   |

### enableViewTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void enableViewTransition(int id, boolean enable)
```

Enable this viewTransition

| Parameters |
|---|---|
| `int id` | of viewTransition |
| `boolean enable` |   |

### gatPathMotionArc

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public int gatPathMotionArc()
```

The transition arc path mode

| Returns |
|---|---|
| `int` |   |

### getConstraintSet

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public ConstraintSet getConstraintSet(Context context, String id)
```

Get the constraintSet given the id

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` |   |
| `https://developer.android.com/reference/java/lang/String.html id` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintSet` |   |

### getConstraintSetIds

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public int[] getConstraintSetIds()
```

Get the list of all Constraint Sets Know to the system

| Returns |
|---|---|
| `int[]` |   |

### getDefinedTransitions

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public ArrayList<MotionScene.Transition> getDefinedTransitions()
```

Get list of Transitions know to the system

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition>` |   |

### getDuration

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public int getDuration()
```

Get Duration of the current transition.

| Returns |
|---|---|
| `int` | duration in milliseconds |

### getInterpolator

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public Interpolator getInterpolator()
```

Get the interpolator define for the current Transition

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/animation/Interpolator.html` |   |

### getKeyFrames

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void getKeyFrames(MotionController motionController)
```

provides the key frames \&CycleFrames to the motion view to

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController motionController` |   |

### getMatchingStateLabels

```
public int[] getMatchingStateLabels(String[] types)
```

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

| Returns |
|---|---|
| `int[]` |   |

### getPathPercent

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public float getPathPercent(View view, int position)
```

Get the path percent (Non functional currently)

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` |   |
| `int position` |   |

| Returns |
|---|---|
| `float` |   |

### getStaggered

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public float getStaggered()
```

Get the staggered value of the current transition. Will default to 0 staggered if there is no current transition.

| Returns |
|---|---|
| `float` |   |

### getTransitionById

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public MotionScene.Transition getTransitionById(int id)
```

Find the transition based on the id

| Parameters |
|---|---|
| `int id` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition` |   |

### getTransitionsWithState

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public List<MotionScene.Transition> getTransitionsWithState(int stateId)
```

Get all transitions that include this state

| Parameters |
|---|---|
| `int stateId` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition>` |   |

### isViewTransitionEnabled

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public boolean isViewTransitionEnabled(int id)
```

Is this view transition enabled

| Parameters |
|---|---|
| `int id` | of viewTransition |

| Returns |
|---|---|
| `boolean` |   |

### lookUpConstraintId

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public int lookUpConstraintId(String id)
```

Used at design time

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` |   |

| Returns |
|---|---|
| `int` |   |

### lookUpConstraintName

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public String lookUpConstraintName(int id)
```

used at design time

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` |   |

### removeTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void removeTransition(MotionScene.Transition transition)
```

Remove the transition with the matching id from the motion scene. If no matching transition is found, it does nothing.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the transition does not have an id. |

### setConstraintSet

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void setConstraintSet(int id, ConstraintSet set)
```

Maps the Constraint set to the id.

| Parameters |
|---|---|
| `int id` | - unique id to represent the ConstraintSet |
| `https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintSet set` | - ConstraintSet to be represented with the id. |

### setDuration

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void setDuration(int duration)
```

Sets the duration of the current transition or the default if there is no current transition

| Parameters |
|---|---|
| `int duration` | in milliseconds |

### setKeyframe

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void setKeyframe(View view, int position, String name, Object value)
```

Set a keyFrame on the current Transition

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` |   |
| `int position` |   |
| `https://developer.android.com/reference/java/lang/String.html name` |   |
| `https://developer.android.com/reference/java/lang/Object.html value` |   |

### setRtl

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void setRtl(boolean rtl)
```

Set Right to left

| Parameters |
|---|---|
| `boolean rtl` |   |

### setTransition

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public void setTransition(MotionScene.Transition transition)
```

Set the transition to be the current transition of the motion scene.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene.Transition transition` | a transition to be set. The transition must exist within the motion scene. (e.g. `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionScene#addTransition(androidx.constraintlayout.motion.widget.MotionScene.Transition)`) |

### stripID

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public static String stripID(String id)
```

Utility to strip the @id/ from an id

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` |   |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` |   |

### validateLayout

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public boolean validateLayout(MotionLayout layout)
```

| Returns |
|---|---|
| `boolean` | true if the layout is valid for the scene. False otherwise. Use it for the debugging purposes. |

### viewTransition

```
public void viewTransition(int id, View[] view)
```

Apply the viewTransition on the list of views

| Parameters |
|---|---|
| `int id` |   |
| `View[] view` |   |

## Protected methods

### onLayout

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

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