PropertyValuesHolder
public class PropertyValuesHolder implements Cloneable
This class holds information about a property and the values that that property should take on during an animation. PropertyValuesHolder objects can be used to create animations with ValueAnimator or ObjectAnimator that operate on several different properties in parallel.
Summary
Public methods |
|
|---|---|
@NonNull PropertyValuesHolder |
clone() |
@NonNull String |
Gets the name of the property that will be animated. |
static @NonNull PropertyValuesHolder |
Constructs and returns a PropertyValuesHolder with a given property name and set of float values. |
static @NonNull PropertyValuesHolder |
Constructs and returns a PropertyValuesHolder with a given property and set of float values. |
static @NonNull PropertyValuesHolder |
Constructs and returns a PropertyValuesHolder with a given property name and set of int values. |
static @NonNull PropertyValuesHolder |
Constructs and returns a PropertyValuesHolder with a given property and set of int values. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder object with the specified property name and set of values. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder object with the specified property and set of values. |
static @NonNull PropertyValuesHolder |
ofMultiFloat(@NonNull String propertyName, @NonNull Path path)Constructs and returns a PropertyValuesHolder with a given property name to use as a multi-float setter. |
static @NonNull PropertyValuesHolder |
ofMultiFloat(@NonNull String propertyName, @NonNull float[][] values)Constructs and returns a PropertyValuesHolder with a given property name and set of |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder with a given property and set of Object values for use with ObjectAnimator multi-value setters. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder object with the specified property name or setter name for use in a multi-float setter function using ObjectAnimator. |
static @NonNull PropertyValuesHolder |
ofMultiInt(@NonNull String propertyName, @NonNull Path path)Constructs and returns a PropertyValuesHolder with a given property name to use as a multi-int setter. |
static @NonNull PropertyValuesHolder |
ofMultiInt(@NonNull String propertyName, @NonNull int[][] values)Constructs and returns a PropertyValuesHolder with a given property name and set of |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder with a given property and set of Object values for use with ObjectAnimator multi-value setters. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder object with the specified property name or setter name for use in a multi-int setter function using ObjectAnimator. |
static @NonNull PropertyValuesHolder |
ofObject(Constructs and returns a PropertyValuesHolder with a given property name and a Path along which the values should be animated. |
static @NonNull PropertyValuesHolder |
Constructs and returns a PropertyValuesHolder with a given property name and set of Object values. |
static @NonNull PropertyValuesHolder |
<V> ofObject(Constructs and returns a PropertyValuesHolder with a given property and a Path along which the values should be animated. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder with a given property and set of Object values. |
static @NonNull PropertyValuesHolder |
@SafeVarargsConstructs and returns a PropertyValuesHolder with a given property and set of Object values. |
void |
setConverter(@Nullable TypeConverter converter)Sets the converter to convert from the values type to the setter's parameter type. |
void |
setEvaluator(@NonNull TypeEvaluator evaluator)The TypeEvaluator will be automatically determined based on the type of values supplied to PropertyValuesHolder. |
void |
setFloatValues(@NonNull float[] values)Set the animated values for this object to this set of floats. |
void |
setIntValues(@NonNull int[] values)Set the animated values for this object to this set of ints. |
void |
setKeyframes(@NonNull Keyframe[] values)Set the animated values for this object to this set of Keyframes. |
void |
setObjectValues(@NonNull Object[] values)Set the animated values for this object to this set of Objects. |
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. |
@NonNull String |
toString() |
Public methods
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.
ofFloat
public static @NonNull PropertyValuesHolder ofFloat(@NonNull String propertyName, @NonNull float[] values)
Constructs and returns a PropertyValuesHolder with a given property name and set of float values.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. |
@NonNull float[] values |
The values that the named property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofFloat
public static @NonNull PropertyValuesHolder ofFloat(@NonNull Property<Object, Float> property, @NonNull float[] values)
Constructs and returns a PropertyValuesHolder with a given property and set of float values.
| Parameters | |
|---|---|
@NonNull Property<Object, Float> property |
The property being animated. Should not be null. |
@NonNull float[] values |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofInt
public static @NonNull PropertyValuesHolder ofInt(@NonNull String propertyName, @NonNull int[] values)
Constructs and returns a PropertyValuesHolder with a given property name and set of int values.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. |
@NonNull int[] values |
The values that the named property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofInt
public static @NonNull PropertyValuesHolder ofInt(@NonNull Property<Object, Integer> property, @NonNull int[] values)
Constructs and returns a PropertyValuesHolder with a given property and set of int values.
| Parameters | |
|---|---|
@NonNull Property<Object, Integer> property |
The property being animated. Should not be null. |
@NonNull int[] values |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofKeyframe
@SafeVarargs
public static @NonNull PropertyValuesHolder ofKeyframe(@NonNull String propertyName, @NonNull Keyframe[] values)
Constructs and returns a PropertyValuesHolder object with the specified property name and set of values. These values can be of any type, but the type should be consistent so that an appropriate TypeEvaluator can be found that matches the common type.
If there is only one value, it is assumed to be the end value of an animation, and an initial value will be derived, if possible, by calling a getter function on the object. Also, if any value is null, the value will be filled in when the animation starts in the same way. This mechanism of automatically getting null values only works if the PropertyValuesHolder object is used in conjunction ObjectAnimator, and with a getter function derived automatically from propertyName, since otherwise PropertyValuesHolder has no way of determining what the value should be.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property associated with this set of values. This can be the actual property name to be used when using a ObjectAnimator object, or just a name used to get animated values, such as if this object is used with an ValueAnimator object. |
@NonNull Keyframe[] values |
The set of values to animate between. |
ofKeyframe
@SafeVarargs
public static @NonNull PropertyValuesHolder ofKeyframe(@NonNull Property property, @NonNull Keyframe[] values)
Constructs and returns a PropertyValuesHolder object with the specified property and set of values. These values can be of any type, but the type should be consistent so that an appropriate androidx.core.animation.TypeEvaluator can be found that matches the common type.
If there is only one value, it is assumed to be the end value of an animation, and an initial value will be derived, if possible, by calling the property's get function. Also, if any value is null, the value will be filled in when the animation starts in the same way. This mechanism of automatically getting null values only works if the PropertyValuesHolder object is used in conjunction with ObjectAnimator, since otherwise PropertyValuesHolder has no way of determining what the value should be.
ofMultiFloat
public static @NonNull PropertyValuesHolder ofMultiFloat(@NonNull String propertyName, @NonNull Path path)
Constructs and returns a PropertyValuesHolder with a given property name to use as a multi-float setter. The values are animated along the path, with the first parameter of the setter set to the x coordinate and the second set to the y coordinate.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. Can also be the case-sensitive name of the entire setter method. Should not be null. The setter must take exactly two |
@NonNull Path path |
The Path along which the values should be animated. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
ofPropertyValuesHolder |
ofMultiFloat
public static @NonNull PropertyValuesHolder ofMultiFloat(@NonNull String propertyName, @NonNull float[][] values)
Constructs and returns a PropertyValuesHolder with a given property name and set of float[] values. At least two float[] values must be supplied, a start and end value. If more values are supplied, the values will be animated from the start, through all intermediate values to the end value. When used with ObjectAnimator, the elements of the array represent the parameters of the setter function.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. Can also be the case-sensitive name of the entire setter method. Should not be null. |
@NonNull float[][] values |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
FloatArrayEvaluator |
|
ofMultiFloat |
ofMultiFloat
@SafeVarargs
public static @NonNull PropertyValuesHolder <V> ofMultiFloat(
@NonNull String propertyName,
@NonNull TypeConverter<V, float[]> converter,
@NonNull TypeEvaluator<V> evaluator,
@NonNull V[] values
)
Constructs and returns a PropertyValuesHolder with a given property and set of Object values for use with ObjectAnimator multi-value setters. The Object values are converted to float[] using the converter.
| Parameters | |
|---|---|
@NonNull String propertyName |
The property being animated or complete name of the setter. Should not be null. |
@NonNull TypeConverter<V, float[]> converter |
Used to convert the animated value to setter parameters. |
@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 |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
ofMultiFloat |
ofMultiFloat
@SafeVarargs
public static @NonNull PropertyValuesHolder <T> ofMultiFloat(
@NonNull String propertyName,
@Nullable TypeConverter<T, float[]> converter,
@NonNull TypeEvaluator<T> evaluator,
@NonNull Keyframe[] values
)
Constructs and returns a PropertyValuesHolder object with the specified property name or setter name for use in a multi-float setter function using ObjectAnimator. The values can be of any type, but the type should be consistent so that the supplied TypeEvaluator can be used to to evaluate the animated value. The converter converts the values to parameters in the setter function.
At least two values must be supplied, a start and an end value.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property to associate with the set of values. This may also be the complete name of a setter function. |
@Nullable TypeConverter<T, float[]> converter |
Converts |
@NonNull TypeEvaluator<T> evaluator |
Used to interpolate between values. |
@NonNull Keyframe[] values |
The values at specific fractional times to evaluate between |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
A PropertyValuesHolder for a multi-float parameter setter. |
ofMultiInt
public static @NonNull PropertyValuesHolder ofMultiInt(@NonNull String propertyName, @NonNull Path path)
Constructs and returns a PropertyValuesHolder with a given property name to use as a multi-int setter. The values are animated along the path, with the first parameter of the setter set to the x coordinate and the second set to the y coordinate.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. Can also be the case-sensitive name of the entire setter method. Should not be null. The setter must take exactly two |
@NonNull Path path |
The Path along which the values should be animated. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
ofPropertyValuesHolder |
ofMultiInt
public static @NonNull PropertyValuesHolder ofMultiInt(@NonNull String propertyName, @NonNull int[][] values)
Constructs and returns a PropertyValuesHolder with a given property name and set of int[] values. At least two int[] values must be supplied, a start and end value. If more values are supplied, the values will be animated from the start, through all intermediate values to the end value. When used with ObjectAnimator, the elements of the array represent the parameters of the setter function.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property being animated. Can also be the case-sensitive name of the entire setter method. Should not be null. |
@NonNull int[][] values |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
IntArrayEvaluator |
|
ofMultiInt |
ofMultiInt
@SafeVarargs
public static @NonNull PropertyValuesHolder <V> ofMultiInt(
@NonNull String propertyName,
@NonNull TypeConverter<V, int[]> converter,
@NonNull TypeEvaluator<V> evaluator,
@NonNull V[] values
)
Constructs and returns a PropertyValuesHolder with a given property and set of Object values for use with ObjectAnimator multi-value setters. The Object values are converted to int[] using the converter.
| Parameters | |
|---|---|
@NonNull String propertyName |
The property being animated or complete name of the setter. Should not be null. |
@NonNull TypeConverter<V, int[]> converter |
Used to convert the animated value to setter parameters. |
@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 |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
ofMultiInt |
|
ofPropertyValuesHolder |
ofMultiInt
@SafeVarargs
public static @NonNull PropertyValuesHolder <T> ofMultiInt(
@NonNull String propertyName,
@Nullable TypeConverter<T, int[]> converter,
@NonNull TypeEvaluator<T> evaluator,
@NonNull Keyframe[] values
)
Constructs and returns a PropertyValuesHolder object with the specified property name or setter name for use in a multi-int setter function using ObjectAnimator. The values can be of any type, but the type should be consistent so that the supplied TypeEvaluator can be used to to evaluate the animated value. The converter converts the values to parameters in the setter function.
At least two values must be supplied, a start and an end value.
| Parameters | |
|---|---|
@NonNull String propertyName |
The name of the property to associate with the set of values. This may also be the complete name of a setter function. |
@Nullable TypeConverter<T, int[]> converter |
Converts |
@NonNull TypeEvaluator<T> evaluator |
Used to interpolate between values. |
@NonNull Keyframe[] values |
The values at specific fractional times to evaluate between |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
A PropertyValuesHolder for a multi-int parameter setter. |
ofObject
public static @NonNull PropertyValuesHolder ofObject(
@NonNull String propertyName,
@Nullable TypeConverter<PointF, Object> converter,
@NonNull Path path
)
Constructs and returns a PropertyValuesHolder with a given property name and a Path along which the values should be animated. This variant supports a TypeConverter to convert from PointF to the target type.
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 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 Path along which the values should be animated. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofObject
public static @NonNull PropertyValuesHolder ofObject(
@NonNull String propertyName,
@NonNull TypeEvaluator evaluator,
@NonNull Object[] values
)
Constructs and returns a PropertyValuesHolder with a given property name and set of Object values. This variant also takes a TypeEvaluator because the system cannot automatically interpolate between objects of unknown type.
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 PropertyValuesHolder. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@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 |
The values that the named property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofObject
public static @NonNull PropertyValuesHolder <V> ofObject(
@NonNull Property<Object, V> property,
@Nullable TypeConverter<PointF, V> converter,
@NonNull Path path
)
Constructs and returns a PropertyValuesHolder with a given property and a Path along which the values should be animated. This variant supports a TypeConverter to convert from PointF to the target type.
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 Property<Object, 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 Path along which the values should be animated. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofObject
@SafeVarargs
public static @NonNull PropertyValuesHolder <V> ofObject(
@NonNull Property property,
@NonNull TypeEvaluator<V> evaluator,
@NonNull V[] values
)
Constructs and returns a PropertyValuesHolder with a given property and set of Object values. This variant also takes a TypeEvaluator because the system cannot automatically interpolate between objects of unknown type.
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 PropertyValuesHolder. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull Property property |
The property being animated. Should not be null. |
@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 |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
ofObject
@SafeVarargs
public static @NonNull PropertyValuesHolder <T, V> ofObject(
@NonNull Property<Object, V> property,
@NonNull TypeConverter<T, V> converter,
@NonNull TypeEvaluator<T> evaluator,
@NonNull T[] values
)
Constructs and returns a PropertyValuesHolder with a given property and set of Object values. This variant also takes a TypeEvaluator because the system cannot automatically interpolate between objects of unknown type. This variant also takes a TypeConverter to convert from 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 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 PropertyValuesHolder. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull Property<Object, V> property |
The property being animated. Should not be null. |
@NonNull TypeConverter<T, V> converter |
Converts the animated object to the Property type. |
@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 |
The values that the property will animate between. |
| Returns | |
|---|---|
@NonNull PropertyValuesHolder |
PropertyValuesHolder The constructed PropertyValuesHolder object. |
| See also | |
|---|---|
setConverter |
|
TypeConverter |
setConverter
public void setConverter(@Nullable TypeConverter converter)
Sets the converter to convert from the values type to the setter's parameter type. If only one value is supplied, converter must be a BidirectionalTypeConverter.
| Parameters | |
|---|---|
@Nullable TypeConverter converter |
The converter to use to convert values. |
setEvaluator
public void setEvaluator(@NonNull TypeEvaluator evaluator)
The TypeEvaluator will be automatically determined based on the type of values supplied to PropertyValuesHolder. The evaluator can be manually set, however, if so desired. This may be important in cases where either the type of the values supplied do not match the way that they should be interpolated between, or if the values are of a custom type or one not currently understood by the animation system. Currently, only values of type float and int (and their Object equivalents: Float and Integer) are correctly interpolated; all other types require setting a TypeEvaluator.
| Parameters | |
|---|---|
@NonNull TypeEvaluator evaluator |
setFloatValues
public void setFloatValues(@NonNull float[] values)
Set the animated values for this object to this set of floats. If there is only one value, it is assumed to be the end value of an animation, and an initial value will be derived, if possible, by calling a getter function on the object. Also, if any value is null, the value will be filled in when the animation starts in the same way. This mechanism of automatically getting null values only works if the PropertyValuesHolder object is used in conjunction ObjectAnimator, and with a getter function derived automatically from propertyName, since otherwise PropertyValuesHolder has no way of determining what the value should be.
| Parameters | |
|---|---|
@NonNull float[] values |
One or more values that the animation will animate between. |
setIntValues
public void setIntValues(@NonNull int[] values)
Set the animated values for this object to this set of ints. If there is only one value, it is assumed to be the end value of an animation, and an initial value will be derived, if possible, by calling a getter function on the object. Also, if any value is null, the value will be filled in when the animation starts in the same way. This mechanism of automatically getting null values only works if the PropertyValuesHolder object is used in conjunction ObjectAnimator, and with a getter function derived automatically from propertyName, since otherwise PropertyValuesHolder has no way of determining what the value should be.
| Parameters | |
|---|---|
@NonNull int[] values |
One or more values that the animation will animate between. |
setKeyframes
public void setKeyframes(@NonNull Keyframe[] values)
Set the animated values for this object to this set of Keyframes.
| Parameters | |
|---|---|
@NonNull Keyframe[] values |
One or more values that the animation will animate between. |
setObjectValues
public void setObjectValues(@NonNull Object[] values)
Set the animated values for this object to this set of Objects. If there is only one value, it is assumed to be the end value of an animation, and an initial value will be derived, if possible, by calling a getter function on the object. Also, if any value is null, the value will be filled in when the animation starts in the same way. This mechanism of automatically getting null values only works if the PropertyValuesHolder object is used in conjunction ObjectAnimator, and with a getter function derived automatically from propertyName, since otherwise PropertyValuesHolder has no way of determining what the value should be.
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 PropertyValuesHolder. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.
| Parameters | |
|---|---|
@NonNull Object[] values |
One or more values that the animation will animate between. |
setProperty
public void setProperty(@NonNull Property property)
Sets the property that will be animated.
Note that if this PropertyValuesHolder object is used with ObjectAnimator, the property must exist on the target object specified in that ObjectAnimator.
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.
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.