MotionSpec

public class MotionSpec


A motion spec contains multiple named motion timings.

Inflate an instance of MotionSpec from XML by creating a Property Animation resource 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

Public methods

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

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

static MotionSpec
createFromResource(Context context, int id)

Inflates an instance of MotionSpec from the given animator resource.

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

Creates and returns an ObjectAnimator that animates the given property.

PropertyValuesHolder[]

Get values for a property in this MotionSpec.

MotionTiming

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

long

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

boolean

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

boolean

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

int
void
setPropertyValues(String name, PropertyValuesHolder[] values)

Set values for a property in this MotionSpec.

void
setTiming(String name, MotionTiming timing)

Sets a MotionTiming with the given name.

String

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