MotionSpec

public class MotionSpec
extends Object

java.lang.Object
   ↳ com.google.android.material.animation.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 <objectAnimator> or a <set> of multiple <objectAnimator>.

<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

MotionSpec()

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 equals(Object o)
<T> ObjectAnimator getAnimator(String name, T target, Property<T, ?> property)

Creates and returns an ObjectAnimator that animates the given property.

PropertyValuesHolder[] getPropertyValues(String name)

Get values for a property in this MotionSpec.

MotionTiming getTiming(String name)

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

long getTotalDuration()

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

boolean hasPropertyValues(String name)

Returns whether this motion spec contains a ERROR(/PropertyValuesHolder[]) with the given name.

boolean hasTiming(String name)

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

int hashCode()
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 toString()

Inherited methods

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.

Parameters
context Context

attributes TypedArray

index int

Returns
MotionSpec

createFromResource

public static MotionSpec createFromResource (Context context, 
                int id)

Inflates an instance of MotionSpec from the given animator resource.

Parameters
context Context

id int

Returns
MotionSpec

equals

public boolean equals (Object o)

Parameters
o Object

Returns
boolean

getAnimator

public ObjectAnimator 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
name String: Name of the property to be animated.

target T: The target whose property is to be animated. See ERROR(/ObjectAnimator#ofPropertyValuesHolder(T, PropertyValuesHolder...)) for more details.

property 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
name String: 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.

Parameters
name String

Returns
MotionTiming

getTotalDuration

public long getTotalDuration ()

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

Returns
long

hasPropertyValues

public boolean hasPropertyValues (String name)

Returns whether this motion spec contains a ERROR(/PropertyValuesHolder[]) with the given name.

Parameters
name String

Returns
boolean

hasTiming

public boolean hasTiming (String name)

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

Parameters
name String

Returns
boolean

hashCode

public int hashCode ()

Returns
int

setPropertyValues

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

Set values for a property in this MotionSpec.

Parameters
name String: Name of the property to set values for, e.g. "width" or "opacity".

values PropertyValuesHolder: Array of PropertyValuesHolder values for the property.

setTiming

public void setTiming (String name, 
                MotionTiming timing)

Sets a MotionTiming with the given name.

Parameters
name String

timing MotionTiming

toString

public String toString ()

Returns
String