# MotionController

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/MotionController.java+class:androidx.constraintlayout.motion.widget.MotionController) Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

*** ** * ** ***


```
public class MotionController
```

<br />

*** ** * ** ***

Contains the picture of a view through a transition and is used to interpolate it. During an transition every view has a MotionController which drives its position.

All parameter which affect a views motion are added to MotionController and then setup() builds out the splines that control the view.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_AS_CONFIGURED() = 4` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_BASIC() = 1` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_CARTESIAN() = 3` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_NONE() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_RECTANGLE() = 5` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_RELATIVE() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#DRAW_PATH_SCREEN() = 6` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#HORIZONTAL_PATH_X() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#HORIZONTAL_PATH_Y() = 3` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#PATH_PERCENT() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#PATH_PERPENDICULAR() = 1` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#ROTATION_LEFT() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#ROTATION_RIGHT() = 1` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#VERTICAL_PATH_X() = 4` |
| `static final int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#VERTICAL_PATH_Y() = 5` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#addKey(androidx.constraintlayout.motion.widget.Key)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/Key key)` Add a key to the MotionController |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getAnimateRelativeTo()()` Will return the id of the view to move relative to. |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getCenter(double,float[],float[])(double p, float[] pos, float[] vel)` Get a center and velocities at the position p |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getCenterX()()` Get the center X of the motion at the current progress |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getCenterY()()` Get the center Y of the motion at the current progress |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getDrawPath()()` returns the draw path mode |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getFinalHeight()()` get the width of the widget at the end of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getFinalWidth()()` get the width of the widget at the end of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getFinalX()()` get the left most position of the widget at the end of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getFinalY()()` get the top most position of the widget at the end of the movement. |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getKeyFrameInfo(int,int[])(int type, int[] info)` Get the keyFrames for the view controlled by this MotionController. the info data structure is of the form 0 length if your are at index i the \[i+len+1\] is the next entry 1 type 1=Attributes, 2=Position, 3=TimeCycle 4=Cycle 5=Trigger 2 position 3 x location 4 y location 5 ... length |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getKeyFramePositions(int[],float[])(int[] type, float[] pos)` Get the keyFrames for the view controlled by this MotionController |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getStartHeight()()` get the width of the widget at the start of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getStartWidth()()` get the width of the widget at the start of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getStartX()()` get the left most position of the widget at the start of the movement. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getStartY()()` get the top most position of the widget at the start of the movement. |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getTransformPivotTarget()()` Get the view to pivot around |
| `https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#getView()()` Get the view that is being controlled |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#remeasure()()` During the next layout call measure then layout |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setDrawPath(int)(int debugMode)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setPathMotionArc(int)(int arc)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setStartState(androidx.constraintlayout.motion.utils.ViewState,android.view.View,int,int,int)( https://developer.android.com/reference/androidx/constraintlayout/motion/utils/ViewState rect, https://developer.android.com/reference/android/view/View.html v, int rotation, int preWidth, int preHeight )` configure the position of the view |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setTransformPivotTarget(int)(int transformPivotTarget)` Set a view to pivot around |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setView(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setup(int,int,float,long)( int parentWidth, int parentHeight, float transitionDuration, long currentTime )` Called after all TimePoints \&Cycles have been added; Spines are evaluated |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#setupRelative(androidx.constraintlayout.motion.widget.MotionController)(https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController motionController)` This ties one motionController to another to allow relative pathes |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionController#toString()()` Debug string |

## Constants

### DRAW_PATH_AS_CONFIGURED

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

```
public static final int DRAW_PATH_AS_CONFIGURED = 4
```

### DRAW_PATH_BASIC

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

```
public static final int DRAW_PATH_BASIC = 1
```

### DRAW_PATH_CARTESIAN

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

```
public static final int DRAW_PATH_CARTESIAN = 3
```

### DRAW_PATH_NONE

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

```
public static final int DRAW_PATH_NONE = 0
```

### DRAW_PATH_RECTANGLE

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

```
public static final int DRAW_PATH_RECTANGLE = 5
```

### DRAW_PATH_RELATIVE

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

```
public static final int DRAW_PATH_RELATIVE = 2
```

### DRAW_PATH_SCREEN

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

```
public static final int DRAW_PATH_SCREEN = 6
```

### HORIZONTAL_PATH_X

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

```
public static final int HORIZONTAL_PATH_X = 2
```

### HORIZONTAL_PATH_Y

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

```
public static final int HORIZONTAL_PATH_Y = 3
```

### PATH_PERCENT

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

```
public static final int PATH_PERCENT = 0
```

### PATH_PERPENDICULAR

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

```
public static final int PATH_PERPENDICULAR = 1
```

### ROTATION_LEFT

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

```
public static final int ROTATION_LEFT = 2
```

### ROTATION_RIGHT

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

```
public static final int ROTATION_RIGHT = 1
```

### VERTICAL_PATH_X

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

```
public static final int VERTICAL_PATH_X = 4
```

### VERTICAL_PATH_Y

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

```
public static final int VERTICAL_PATH_Y = 5
```

## Public methods

### addKey

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

```
public void addKey(Key key)
```

Add a key to the MotionController

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

### getAnimateRelativeTo

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

```
public int getAnimateRelativeTo()
```

Will return the id of the view to move relative to. The position at the start and then end will be viewed relative to this view -1 is the return value if NOT in polar mode

| Returns |
|---|---|
| `int` | the view id of the view this is in polar mode to or -1 if not in polar |

### getCenter

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

```
public void getCenter(double p, float[] pos, float[] vel)
```

Get a center and velocities at the position p

| Parameters |
|---|---|
| `double p` |   |
| `float[] pos` |   |
| `float[] vel` |   |

### getCenterX

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

```
public float getCenterX()
```

Get the center X of the motion at the current progress

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

### getCenterY

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

```
public float getCenterY()
```

Get the center Y of the motion at the current progress

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

### getDrawPath

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

```
public int getDrawPath()
```

returns the draw path mode

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

### getFinalHeight

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

```
public float getFinalHeight()
```

get the width of the widget at the end of the movement.

| Returns |
|---|---|
| `float` | the height at the end |

### getFinalWidth

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

```
public float getFinalWidth()
```

get the width of the widget at the end of the movement.

| Returns |
|---|---|
| `float` | the width at the end |

### getFinalX

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

```
public float getFinalX()
```

get the left most position of the widget at the end of the movement.

| Returns |
|---|---|
| `float` | the left most position |

### getFinalY

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

```
public float getFinalY()
```

get the top most position of the widget at the end of the movement. Positive is down.

| Returns |
|---|---|
| `float` | the top most position |

### getKeyFrameInfo

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

```
public int getKeyFrameInfo(int type, int[] info)
```

Get the keyFrames for the view controlled by this MotionController. the info data structure is of the form 0 length if your are at index i the \[i+len+1\] is the next entry 1 type 1=Attributes, 2=Position, 3=TimeCycle 4=Cycle 5=Trigger 2 position 3 x location 4 y location 5 ... length

| Parameters |
|---|---|
| `int[] info` | is a data structure array of int that holds info on each keyframe |

| Returns |
|---|---|
| `int` | Number of keyFrames found |

### getKeyFramePositions

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

```
public int getKeyFramePositions(int[] type, float[] pos)
```

Get the keyFrames for the view controlled by this MotionController

| Parameters |
|---|---|
| `int[] type` | is position(0-100) + 1000\*mType(1=Attr, 2=Pos, 3=TimeCycle 4=Cycle 5=Trigger |
| `float[] pos` | the x\&y position of the keyFrame along the path |

| Returns |
|---|---|
| `int` | Number of keyFrames found |

### getStartHeight

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

```
public float getStartHeight()
```

get the width of the widget at the start of the movement.

| Returns |
|---|---|
| `float` | the height at the start |

### getStartWidth

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

```
public float getStartWidth()
```

get the width of the widget at the start of the movement.

| Returns |
|---|---|
| `float` | the width at the start |

### getStartX

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

```
public float getStartX()
```

get the left most position of the widget at the start of the movement.

| Returns |
|---|---|
| `float` | the left most position |

### getStartY

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

```
public float getStartY()
```

get the top most position of the widget at the start of the movement. Positive is down.

| Returns |
|---|---|
| `float` | the top most position |

### getTransformPivotTarget

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

```
public int getTransformPivotTarget()
```

Get the view to pivot around

| Returns |
|---|---|
| `int` | id of view or UNSET if not set |

### getView

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

```
public View getView()
```

Get the view that is being controlled

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

### remeasure

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

```
public void remeasure()
```

During the next layout call measure then layout

### setDrawPath

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

```
public void setDrawPath(int debugMode)
```

### setPathMotionArc

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

```
public void setPathMotionArc(int arc)
```

### setStartState

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

```
public void setStartState(
    ViewState rect,
    View v,
    int rotation,
    int preWidth,
    int preHeight
)
```

configure the position of the view

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/ViewState rect` |   |
| `https://developer.android.com/reference/android/view/View.html v` |   |
| `int rotation` |   |
| `int preWidth` |   |
| `int preHeight` |   |

### setTransformPivotTarget

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

```
public void setTransformPivotTarget(int transformPivotTarget)
```

Set a view to pivot around

| Parameters |
|---|---|
| `int transformPivotTarget` | id of view |

### setView

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

```
public void setView(View view)
```

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

### setup

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

```
public void setup(
    int parentWidth,
    int parentHeight,
    float transitionDuration,
    long currentTime
)
```

Called after all TimePoints \&Cycles have been added; Spines are evaluated

### setupRelative

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

```
public void setupRelative(MotionController motionController)
```

This ties one motionController to another to allow relative pathes

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

### toString

```
public String toString()
```

Debug string

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