# MotionSpec

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/animation/MotionSpec.java)

*** ** * ** ***


```
public class MotionSpec
```

<br />

*** ** * ** ***

A motion spec contains multiple named `https://developer.android.com/reference/com/google/android/material/animation/MotionTiming`.

Inflate an instance of MotionSpec from XML by creating a [Property Animation resource](https://developer.android.com/guide/topics/resources/animation-resource.html#Property) in `res/animator`. The file must contain an `<objectAnimator>` or a `<set>` of object animators.

This class will store a map of String keys to MotionTiming values. Each animator's `
android:propertyName` attribute will be used as the key, while the other attributes `
android:startOffset`, `android:duration`, `android:interpolator`, `
android:repeatCount`, and `android:repeatMode` will be used to create the MotionTiming instance.

A motion spec resource can either be an or a of multiple .

```
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <objectAnimator
      android:propertyName="alpha"
      android:startOffset="0"
      android:duration="100"
      android:interpolator="@interpolator/mtrl_fast_out_slow_in"/>
  <objectAnimator
      android:propertyName="translation"
      android:startOffset="50"
      android:duration="150"/>
</set>
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#MotionSpec()()` |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/com/google/android/material/animation/MotionSpec` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#createFromAttribute(Context,TypedArray,int)(Context context, TypedArray attributes, int index)` Inflates an instance of MotionSpec from the animator resource indexed in the given attributes array. |
| `static https://developer.android.com/reference/com/google/android/material/animation/MotionSpec` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#createFromResource(Context,int)(Context context, int id)` Inflates an instance of MotionSpec from the given animator resource. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o)` |
| `ObjectAnimator` | `<T> https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#getAnimator(java.lang.String,T,Property<T,?>)(https://developer.android.com/reference/java/lang/String name, T target, Property<T, ?> property)` Creates and returns an ObjectAnimator that animates the given property. |
| `PropertyValuesHolder[]` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#getPropertyValues(java.lang.String)(https://developer.android.com/reference/java/lang/String name)` Get values for a property in this MotionSpec. |
| `https://developer.android.com/reference/com/google/android/material/animation/MotionTiming` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#getTiming(java.lang.String)(https://developer.android.com/reference/java/lang/String name)` Returns the MotionTiming with the given name, or throws IllegalArgumentException if it does not exist. |
| `long` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#getTotalDuration()()` Returns the total duration of this motion spec, which is the maximum delay+duration of its motion timings. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#hasPropertyValues(java.lang.String)(https://developer.android.com/reference/java/lang/String name)` Returns whether this motion spec contains a PropertyValuesHolder with the given name. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#hasTiming(java.lang.String)(https://developer.android.com/reference/java/lang/String name)` Returns whether this motion spec contains a MotionTiming with the given name. |
| `int` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#hashCode()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#setPropertyValues(java.lang.String,PropertyValuesHolder[])(https://developer.android.com/reference/java/lang/String name, PropertyValuesHolder[] values)` Set values for a property in this MotionSpec. |
| `void` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#setTiming(java.lang.String,com.google.android.material.animation.MotionTiming)(https://developer.android.com/reference/java/lang/String name, https://developer.android.com/reference/com/google/android/material/animation/MotionTiming timing)` Sets a MotionTiming with the given name. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/com/google/android/material/animation/MotionSpec#toString()()` |

## Public constructors

### MotionSpec

```
public MotionSpec()
```

## Public methods

### createFromAttribute

```
public static MotionSpec createFromAttribute(Context context, TypedArray attributes, int index)
```

Inflates an instance of MotionSpec from the animator resource indexed in the given attributes array.

### createFromResource

```
public static MotionSpec createFromResource(Context context, int id)
```

Inflates an instance of MotionSpec from the given animator resource.

### equals

```
public boolean equals(Object o)
```

### getAnimator

```
public ObjectAnimator <T> getAnimator(String name, T target, Property<T, ?> property)
```

Creates and returns an ObjectAnimator that animates the given property. This can be added to an AnimatorSet to play multiple synchronized animations.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String name` | Name of the property to be animated. |
| `T target` | The target whose property is to be animated. See ofPropertyValuesHolder for more details. |
| `Property<T, ?> property` | The Property object being animated. |

| Returns |
|---|---|
| `ObjectAnimator` | An ObjectAnimator which animates the given property. |

### getPropertyValues

```
public PropertyValuesHolder[] getPropertyValues(String name)
```

Get values for a property in this MotionSpec.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String name` | Name of the property to get values for, e.g. "width" or "opacity". |

| Returns |
|---|---|
| `PropertyValuesHolder[]` | Array of PropertyValuesHolder values for the property. |

### getTiming

```
public MotionTiming getTiming(String name)
```

Returns the MotionTiming with the given name, or throws IllegalArgumentException if it does not exist.

### getTotalDuration

```
public long getTotalDuration()
```

Returns the total duration of this motion spec, which is the maximum delay+duration of its motion timings.

### hasPropertyValues

```
public boolean hasPropertyValues(String name)
```

Returns whether this motion spec contains a PropertyValuesHolder with the given name.

### hasTiming

```
public boolean hasTiming(String name)
```

Returns whether this motion spec contains a MotionTiming with the given name.

### hashCode

```
public int hashCode()
```

### setPropertyValues

```
public void setPropertyValues(String name, PropertyValuesHolder[] values)
```

Set values for a property in this MotionSpec.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String name` | Name of the property to set values for, e.g. "width" or "opacity". |
| `PropertyValuesHolder[] values` | Array of PropertyValuesHolder values for the property. |

### setTiming

```
public void setTiming(String name, MotionTiming timing)
```

Sets a MotionTiming with the given name.

### toString

```
public String toString()
```