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)
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 hasTiming(String name)

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

int hashCode()
void setTiming(String name, MotionTiming timing)

Sets a MotionTiming with the given name.

String toString()

Inherited methods

From class java.lang.Object

Public constructors

MotionSpec

MotionSpec ()

Public methods

createFromAttribute

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

MotionSpec createFromResource (Context context, 
                int id)

Inflates an instance of MotionSpec from the given animator resource.

Parameters
context Context

id int

Returns
MotionSpec

equals

boolean equals (Object o)

Parameters
o Object

Returns
boolean

getTiming

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

long getTotalDuration ()

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

Returns
long

hasTiming

boolean hasTiming (String name)

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

Parameters
name String

Returns
boolean

hashCode

int hashCode ()

Returns
int

setTiming

void setTiming (String name, 
                MotionTiming timing)

Sets a MotionTiming with the given name.

Parameters
name String

timing MotionTiming

toString

String toString ()

Returns
String