ObjectAnimator
public final class ObjectAnimator extends ValueAnimator
| java.lang.Object | |||
| ↳ | androidx.core.animation.Animator | ||
| ↳ | androidx.core.animation.ValueAnimator | ||
| ↳ | androidx.core.animation.ObjectAnimator |
This subclass of ValueAnimator provides support for animating properties on target objects. The constructors of this class take parameters to define the target object that will be animated as well as the name of the property that will be animated. Appropriate set/get functions are then determined internally and the animation will call these functions as necessary to animate the property.
ObjectAnimator supports the use of PropertyValuesHolder and Keyframe in resource files to create more complex animations. Using PropertyValuesHolders allows animators to animate several properties in parallel.
Using Keyframes allows animations to follow more complex paths from the start to the end values. Note that you can specify explicit fractional values (from 0 to 1) for each keyframe to determine when, in the overall duration, the animation should arrive at that value. Alternatively, you can leave the fractions off and the keyframes will be equally distributed within the total duration. Also, a keyframe with no value will derive its value from the target object when the animator starts, just like animators with only one value specified. In addition, an optional interpolator can be specified. The interpolator will be applied on the interval between the keyframe that the interpolator is set on and the previous keyframe. When no interpolator is supplied, the default AccelerateDecelerateInterpolator will be used.
| See also | |
|---|---|
setPropertyName |
Summary
Public constructors |
|---|
|
Creates a new ObjectAnimator object. |
Public methods |
|
|---|---|
@NonNull ObjectAnimator |
clone() |
@NonNull String |
Returns the name of this animator for debugging purposes. |
@NonNull String |
Gets the name of the property that will be animated. |
@Nullable Object |
The target object whose property will be animated by this animation |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between color values. |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between color values. |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between float values. |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between float values. |
static @NonNull ObjectAnimator |
ofFloat(Constructs and returns an ObjectAnimator that animates coordinates along a |
static @NonNull ObjectAnimator |
<T> ofFloat(Constructs and returns an ObjectAnimator that animates coordinates along a |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between int values. |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates between int values. |
static @NonNull ObjectAnimator |
ofInt(Constructs and returns an ObjectAnimator that animates coordinates along a |
static @NonNull ObjectAnimator |
<T> ofInt(Constructs and returns an ObjectAnimator that animates coordinates along a |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates the target using a multi-float setter along the given |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates over float values for a multiple parameters setter. |
static @NonNull ObjectAnimator |
@SafeVarargsConstructs and returns an ObjectAnimator that animates over values for a multiple float parameters setter. |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates the target using a multi-int setter along the given |
static @NonNull ObjectAnimator |
Constructs and returns an ObjectAnimator that animates over int values for a multiple parameters setter. |
static @NonNull ObjectAnimator |
@SafeVarargsConstructs and returns an ObjectAnimator that animates over values for a multiple int parameters setter. |
static @NonNull ObjectAnimator |
ofObject(Constructs and returns an ObjectAnimator that animates a property along a |
static @NonNull ObjectAnimator |
ofObject(Constructs and returns an ObjectAnimator that animates between Object values. |
static @NonNull ObjectAnimator |
<T, V> ofObject(Constructs and returns an ObjectAnimator that animates a property along a |
static @NonNull ObjectAnimator |
@SafeVarargsConstructs and returns an ObjectAnimator that animates between Object values. |
static @NonNull ObjectAnimator |
@SafeVarargsConstructs and returns an ObjectAnimator that animates between Object values. |
static @NonNull ObjectAnimator |
ofPropertyValuesHolder(Constructs and returns an ObjectAnimator that animates between the sets of values specified in |
void |
setAutoCancel(boolean cancel)autoCancel controls whether an ObjectAnimator will be canceled automatically when any other ObjectAnimator with the same target and properties is started. |
@NonNull ObjectAnimator |
setDuration(long duration)Sets the length of the animation. |
void |
setFloatValues(@NonNull float[] values)Sets float values that will be animated between. |
void |
setIntValues(@NonNull int[] values)Sets int values that will be animated between. |
void |
setObjectValues(@NonNull Object[] values)Sets the values to animate between for this animation. |
void |
setProperty(@NonNull Property property)Sets the property that will be animated. |
void |
setPropertyName(@NonNull String propertyName)Sets the name of the property that will be animated. |
void |
Sets the target object whose property will be animated by this animation. |
void |
This method tells the object to use appropriate information to extract ending values for the animation. |
void |
This method tells the object to use appropriate information to extract starting values for the animation. |
void |
start()Starts this animation. |
@NonNull String |
toString() |
Inherited Constants |
||||||
|---|---|---|---|---|---|---|
|
||||||
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
ObjectAnimator
public ObjectAnimator()
Creates a new ObjectAnimator object. This default constructor is primarily for use internally; the other constructors which take parameters are more generally useful.
Public methods
getNameForTrace
public @NonNull String getNameForTrace()
Returns the name of this animator for debugging purposes.
getPropertyName
public @NonNull String getPropertyName()
Gets the name of the property that will be animated. This name will be used to derive a setter function that will be called to set animated values. For example, a property name of foo will result in a call to the function setFoo() on the target object. If either valueFrom or valueTo is null, then a getter function will also be derived and called.
If this animator was created with a Property object instead of the string name of a property, then this method will return the name of that Property object instead. If this animator was created with one or more PropertyValuesHolder objects, then this method will return the name of that object (if there was just one) or a comma-separated list of all of the names (if there are more than one).
getTarget
public @Nullable Object getTarget()
The target object whose property will be animated by this animation
ofArgb
public static @NonNull ObjectAnimator ofArgb(
@NonNull Object target,
@NonNull String propertyName,
@NonNull int[] values
)
Constructs and returns an ObjectAnimator that animates between color values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object should have a public method on it called |
@NonNull String propertyName |
The name of the property being animated. |
@NonNull int[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofArgb
public static @NonNull ObjectAnimator <T> ofArgb(
@NonNull T target,
@NonNull Property<T, Integer> property,
@NonNull int[] values
)
Constructs and returns an ObjectAnimator that animates between color values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, Integer> property |
The property being animated. |
@NonNull int[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofFloat
public static @NonNull ObjectAnimator ofFloat(
@NonNull Object target,
@NonNull String propertyName,
@NonNull float[] values
)
Constructs and returns an ObjectAnimator that animates between float values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object should have a public method on it called |
@NonNull String propertyName |
The name of the property being animated. |
@NonNull float[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofFloat
public static @NonNull ObjectAnimator <T> ofFloat(
@NonNull T target,
@NonNull Property<T, Float> property,
@NonNull float[] values
)
Constructs and returns an ObjectAnimator that animates between float values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, Float> property |
The property being animated. |
@NonNull float[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofFloat
public static @NonNull ObjectAnimator ofFloat(
@NonNull Object target,
@Nullable String xPropertyName,
@Nullable String yPropertyName,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are floats that are set to separate properties designated by xPropertyName and yPropertyName.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose properties are to be animated. This object should have public methods on it called |
@Nullable String xPropertyName |
The name of the property for the x coordinate being animated. |
@Nullable String yPropertyName |
The name of the property for the y coordinate being animated. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofFloat
public static @NonNull ObjectAnimator <T> ofFloat(
@NonNull T target,
@Nullable Property<T, Float> xProperty,
@Nullable Property<T, Float> yProperty,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are floats that are set to separate properties, xProperty and yProperty.
| Parameters | |
|---|---|
@NonNull T target |
The object whose properties are to be animated. |
@Nullable Property<T, Float> xProperty |
The property for the x coordinate being animated. |
@Nullable Property<T, Float> yProperty |
The property for the y coordinate being animated. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofInt
public static @NonNull ObjectAnimator ofInt(
@NonNull Object target,
@NonNull String propertyName,
@NonNull int[] values
)
Constructs and returns an ObjectAnimator that animates between int values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object should have a public method on it called |
@NonNull String propertyName |
The name of the property being animated. |
@NonNull int[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofInt
public static @NonNull ObjectAnimator <T> ofInt(
@NonNull T target,
@NonNull Property<T, Integer> property,
@NonNull int[] values
)
Constructs and returns an ObjectAnimator that animates between int values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, Integer> property |
The property being animated. |
@NonNull int[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofInt
public static @NonNull ObjectAnimator ofInt(
@NonNull Object target,
@NonNull String xPropertyName,
@NonNull String yPropertyName,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are integers that are set to separate properties designated by xPropertyName and yPropertyName.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose properties are to be animated. This object should have public methods on it called |
@NonNull String xPropertyName |
The name of the property for the x coordinate being animated. |
@NonNull String yPropertyName |
The name of the property for the y coordinate being animated. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofInt
public static @NonNull ObjectAnimator <T> ofInt(
@NonNull T target,
@Nullable Property<T, Integer> xProperty,
@Nullable Property<T, Integer> yProperty,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are integers that are set to separate properties, xProperty and yProperty.
| Parameters | |
|---|---|
@NonNull T target |
The object whose properties are to be animated. |
@Nullable Property<T, Integer> xProperty |
The property for the x coordinate being animated. |
@Nullable Property<T, Integer> yProperty |
The property for the y coordinate being animated. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofMultiFloat
public static @NonNull ObjectAnimator ofMultiFloat(
@NonNull Object target,
@NonNull String propertyName,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates the target using a multi-float setter along the given Path. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are float x and y coordinates used in the first and second parameter of the setter, respectively.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofMultiFloat
public static @NonNull ObjectAnimator ofMultiFloat(
@NonNull Object target,
@NonNull String propertyName,
@NonNull float[][] values
)
Constructs and returns an ObjectAnimator that animates over float values for a multiple parameters setter. Only public methods that take only float parameters are supported. Each float[] contains a complete set of parameters to the setter method. At least two float[] values must be provided, a start and end. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull float[][] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofMultiFloat
@SafeVarargs
public static @NonNull ObjectAnimator <T> ofMultiFloat(
@NonNull Object target,
@NonNull String propertyName,
@NonNull TypeConverter<T, float[]> converter,
@NonNull TypeEvaluator<T> evaluator,
@NonNull T[] values
)
Constructs and returns an ObjectAnimator that animates over values for a multiple float parameters setter. Only public methods that take only float parameters are supported.
At least two values must be provided, a start and end. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull TypeConverter<T, float[]> converter |
Converts T objects into float parameters for the multi-value setter. |
@NonNull TypeEvaluator<T> evaluator |
A TypeEvaluator that will be called on each animation frame to provide the necessary interpolation between the Object values to derive the animated value. |
@NonNull T[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofMultiInt
public static @NonNull ObjectAnimator ofMultiInt(
@NonNull Object target,
@NonNull String propertyName,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates the target using a multi-int setter along the given Path. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. In this variation, the coordinates are integer x and y coordinates used in the first and second parameter of the setter, respectively.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofMultiInt
public static @NonNull ObjectAnimator ofMultiInt(
@NonNull Object target,
@NonNull String propertyName,
@NonNull int[][] values
)
Constructs and returns an ObjectAnimator that animates over int values for a multiple parameters setter. Only public methods that take only int parameters are supported. Each int[] contains a complete set of parameters to the setter method. At least two int[] values must be provided, a start and end. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull int[][] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofMultiInt
@SafeVarargs
public static @NonNull ObjectAnimator <T> ofMultiInt(
@NonNull Object target,
@NonNull String propertyName,
@NonNull TypeConverter<T, int[]> converter,
@NonNull TypeEvaluator<T> evaluator,
@NonNull T[] values
)
Constructs and returns an ObjectAnimator that animates over values for a multiple int parameters setter. Only public methods that take only int parameters are supported.
At least two values must be provided, a start and end. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object may have a public method on it called |
@NonNull String propertyName |
The name of the property being animated or the name of the setter method. |
@NonNull TypeConverter<T, int[]> converter |
Converts T objects into int parameters for the multi-value setter. |
@NonNull TypeEvaluator<T> evaluator |
A TypeEvaluator that will be called on each animation frame to provide the necessary interpolation between the Object values to derive the animated value. |
@NonNull T[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofObject
public static @NonNull ObjectAnimator ofObject(
@NonNull Object target,
@NonNull String propertyName,
@Nullable TypeConverter<PointF, Object> converter,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates a property along a Path. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. This variant animates the coordinates in a PointF to follow the Path. If the Property associated with propertyName uses a type other than PointF, converter can be used to change from PointF to the type associated with the Property.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object should have a public method on it called |
@NonNull String propertyName |
The name of the property being animated. |
@Nullable TypeConverter<PointF, Object> converter |
Converts a PointF to the type associated with the setter. May be null if conversion is unnecessary. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofObject
public static @NonNull ObjectAnimator ofObject(
@NonNull Object target,
@NonNull String propertyName,
@NonNull TypeEvaluator evaluator,
@NonNull Object[] values
)
Constructs and returns an ObjectAnimator that animates between Object values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
Note: The values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. This object should have a public method on it called |
@NonNull String propertyName |
The name of the property being animated. |
@NonNull TypeEvaluator evaluator |
A TypeEvaluator that will be called on each animation frame to provide the necessary interpolation between the Object values to derive the animated value. |
@NonNull Object[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofObject
public static @NonNull ObjectAnimator <T, V> ofObject(
@NonNull T target,
@NonNull Property<T, V> property,
@Nullable TypeConverter<PointF, V> converter,
@NonNull Path path
)
Constructs and returns an ObjectAnimator that animates a property along a Path. A Path animation moves in two dimensions, animating coordinates (x, y) together to follow the line. This variant animates the coordinates in a PointF to follow the Path. If property uses a type other than PointF, converter can be used to change from PointF to the type associated with the Property.
The PointF passed to converter or property, if converter is null, is reused on each animation frame and should not be stored by the setter or TypeConverter.
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, V> property |
The property being animated. Should not be null. |
@Nullable TypeConverter<PointF, V> converter |
Converts a PointF to the type associated with the setter. May be null if conversion is unnecessary. |
@NonNull Path path |
The |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate along |
ofObject
@SafeVarargs
public static @NonNull ObjectAnimator <T, V> ofObject(
@NonNull T target,
@NonNull Property<T, V> property,
@NonNull TypeEvaluator<V> evaluator,
@NonNull V[] values
)
Constructs and returns an ObjectAnimator that animates between Object values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).
Note: The values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, V> property |
The property being animated. |
@NonNull TypeEvaluator<V> evaluator |
A TypeEvaluator that will be called on each animation frame to provide the necessary interpolation between the Object values to derive the animated value. |
@NonNull V[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofObject
@SafeVarargs
public static @NonNull ObjectAnimator <T, V, P> ofObject(
@NonNull T target,
@NonNull Property<T, P> property,
@NonNull TypeConverter<V, P> converter,
@NonNull TypeEvaluator<V> evaluator,
@NonNull V[] values
)
Constructs and returns an ObjectAnimator that animates between Object values. A single value implies that that value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when start is called for the first time. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation). This variant supplies a TypeConverter to convert from the animated values to the type of the property. If only one value is supplied, the TypeConverter must be a BidirectionalTypeConverter to retrieve the current value.
Note: The values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull T target |
The object whose property is to be animated. |
@NonNull Property<T, P> property |
The property being animated. |
@NonNull TypeConverter<V, P> converter |
Converts the animated object to the Property type. |
@NonNull TypeEvaluator<V> evaluator |
A TypeEvaluator that will be called on each animation frame to provide the necessary interpolation between the Object values to derive the animated value. |
@NonNull V[] values |
A set of values that the animation will animate between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
ofPropertyValuesHolder
public static @NonNull ObjectAnimator ofPropertyValuesHolder(
@NonNull Object target,
@NonNull PropertyValuesHolder[] values
)
Constructs and returns an ObjectAnimator that animates between the sets of values specified in PropertyValueHolder objects. This variant should be used when animating several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows you to associate a set of animation values with a property name.
| Parameters | |
|---|---|
@NonNull Object target |
The object whose property is to be animated. Depending on how the PropertyValuesObjects were constructed, the target object should either have the |
@NonNull PropertyValuesHolder[] values |
A set of PropertyValuesHolder objects whose values will be animated between over time. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
An ObjectAnimator object that is set up to animate between the given values. |
setAutoCancel
public void setAutoCancel(boolean cancel)
autoCancel controls whether an ObjectAnimator will be canceled automatically when any other ObjectAnimator with the same target and properties is started. Setting this flag may make it easier to run different animators on the same target object without having to keep track of whether there are conflicting animators that need to be manually canceled. Canceling animators must have the same exact set of target properties, in the same order.
| Parameters | |
|---|---|
boolean cancel |
Whether future ObjectAnimators with the same target and properties as this ObjectAnimator will cause this ObjectAnimator to be canceled. |
setDuration
public @NonNull ObjectAnimator setDuration(long duration)
Sets the length of the animation. The default duration is 300 milliseconds.
| Parameters | |
|---|---|
long duration |
The length of the animation, in milliseconds. |
| Returns | |
|---|---|
@NonNull ObjectAnimator |
ObjectAnimator The object called with setDuration(). This return value makes it easier to compose statements together that construct and then set the duration, as in |
setFloatValues
public void setFloatValues(@NonNull float[] values)
Sets float values that will be animated between. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.
If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.
| Parameters | |
|---|---|
@NonNull float[] values |
A set of values that the animation will animate between over time. |
setIntValues
public void setIntValues(@NonNull int[] values)
Sets int values that will be animated between. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.
If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.
| Parameters | |
|---|---|
@NonNull int[] values |
A set of values that the animation will animate between over time. |
setObjectValues
public void setObjectValues(@NonNull Object[] values)
Sets the values to animate between for this animation. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.
Note: The Object values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.
There should be a TypeEvaluator set on the ValueAnimator that knows how to interpolate between these value objects. ValueAnimator only knows how to interpolate between the primitive types specified in the other setValues() methods.
| Parameters | |
|---|---|
@NonNull Object[] values |
The set of values to animate between. |
setProperty
public void setProperty(@NonNull Property property)
Sets the property that will be animated. Property objects will take precedence over properties specified by the setPropertyName method. Animations should be set up to use one or the other, not both.
setPropertyName
public void setPropertyName(@NonNull String propertyName)
Sets the name of the property that will be animated. This name is used to derive a setter function that will be called to set animated values. For example, a property name of foo will result in a call to the function setFoo() on the target object. If either valueFrom or valueTo is null, then a getter function will also be derived and called.
For best performance of the mechanism that calls the setter function determined by the name of the property being animated, use float or int typed values, and make the setter function for those properties have a void return value. This will cause the code to take an optimized path for these constrained circumstances. Other property types and return types will work, but will have more overhead in processing the requests due to normal reflection mechanisms.
Note that the setter function derived from this property name must take the same parameter type as the valueFrom and valueTo properties, otherwise the call to the setter function will fail.
If this ObjectAnimator has been set up to animate several properties together, using more than one PropertyValuesHolder objects, then setting the propertyName simply sets the propertyName in the first of those PropertyValuesHolder objects.
setTarget
public void setTarget(@Nullable Object target)
Sets the target object whose property will be animated by this animation. Not all subclasses operate on target objects (for example, ValueAnimator, but this method is on the superclass for the convenience of dealing generically with those subclasses that do handle targets.
Note: The target is stored as a weak reference internally to avoid leaking resources by having animators directly reference old targets. Therefore, you should ensure that animator targets always have a hard reference elsewhere.
setupEndValues
public void setupEndValues()
This method tells the object to use appropriate information to extract ending values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.
setupStartValues
public void setupStartValues()
This method tells the object to use appropriate information to extract starting values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.
start
public void start()
Starts this animation. If the animation has a nonzero startDelay, the animation will start running after that delay elapses. A non-delayed animation will have its initial value(s) set immediately, followed by calls to onAnimationStart for any listeners of this animator.
The animation started by calling this method will be run on the thread that called this method. This thread should have a Looper on it (a runtime exception will be thrown if this is not the case). Also, if the animation will animate properties of objects in the view hierarchy, then the calling thread should be the UI thread for that view hierarchy.