public final class ObjectAnimator extends ValueAnimator
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.
Animators can be created from either code or resource files, as shown here:
When using resource files, it is possible to use PropertyValuesHolder
and
Keyframe
to create more complex animations. Using PropertyValuesHolders
allows animators to animate several properties in parallel, as shown in this sample:
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.
For more information about animating with ObjectAnimator
, read the
Property
Animation developer guide.
setPropertyName(String)
ValueAnimator.AnimatorUpdateListener, ValueAnimator.RepeatMode
Animator.AnimatorListener, Animator.AnimatorPauseListener
INFINITE, RESTART, REVERSE
DURATION_INFINITE
Constructor and Description |
---|
ObjectAnimator()
Creates a new ObjectAnimator object.
|
Modifier and Type | Method and Description |
---|---|
ObjectAnimator |
clone()
Creates and returns a copy of this object.
|
String |
getPropertyName()
Gets the name of the property that will be animated.
|
Object |
getTarget()
The target object whose property will be animated by this animation
|
static ObjectAnimator |
ofArgb(Object target,
String propertyName,
int... values)
Constructs and returns an ObjectAnimator that animates between color values.
|
static <T> ObjectAnimator |
ofArgb(T target,
Property<T,Integer> property,
int... values)
Constructs and returns an ObjectAnimator that animates between color values.
|
static ObjectAnimator |
ofFloat(Object target,
String propertyName,
float... values)
Constructs and returns an ObjectAnimator that animates between float values.
|
static ObjectAnimator |
ofFloat(Object target,
String xPropertyName,
String yPropertyName,
Path path)
Constructs and returns an ObjectAnimator that animates coordinates along a
Path
using two properties. |
static <T> ObjectAnimator |
ofFloat(T target,
Property<T,Float> property,
float... values)
Constructs and returns an ObjectAnimator that animates between float values.
|
static <T> ObjectAnimator |
ofFloat(T target,
Property<T,Float> xProperty,
Property<T,Float> yProperty,
Path path)
Constructs and returns an ObjectAnimator that animates coordinates along a
Path
using two properties. |
static ObjectAnimator |
ofInt(Object target,
String propertyName,
int... values)
Constructs and returns an ObjectAnimator that animates between int values.
|
static ObjectAnimator |
ofInt(Object target,
String xPropertyName,
String yPropertyName,
Path path)
Constructs and returns an ObjectAnimator that animates coordinates along a
Path
using two properties. |
static <T> ObjectAnimator |
ofInt(T target,
Property<T,Integer> property,
int... values)
Constructs and returns an ObjectAnimator that animates between int values.
|
static <T> ObjectAnimator |
ofInt(T target,
Property<T,Integer> xProperty,
Property<T,Integer> yProperty,
Path path)
Constructs and returns an ObjectAnimator that animates coordinates along a
Path
using two properties. |
static ObjectAnimator |
ofMultiFloat(Object target,
String propertyName,
float[][] values)
Constructs and returns an ObjectAnimator that animates over float values for a multiple
parameters setter.
|
static ObjectAnimator |
ofMultiFloat(Object target,
String propertyName,
Path path)
Constructs and returns an ObjectAnimator that animates the target using a multi-float setter
along the given
Path . |
static <T> ObjectAnimator |
ofMultiFloat(Object target,
String propertyName,
TypeConverter<T,float[]> converter,
TypeEvaluator<T> evaluator,
T... values)
Constructs and returns an ObjectAnimator that animates over values for a multiple float
parameters setter.
|
static ObjectAnimator |
ofMultiInt(Object target,
String propertyName,
int[][] values)
Constructs and returns an ObjectAnimator that animates over int values for a multiple
parameters setter.
|
static ObjectAnimator |
ofMultiInt(Object target,
String propertyName,
Path path)
Constructs and returns an ObjectAnimator that animates the target using a multi-int setter
along the given
Path . |
static <T> ObjectAnimator |
ofMultiInt(Object target,
String propertyName,
TypeConverter<T,int[]> converter,
TypeEvaluator<T> evaluator,
T... values)
Constructs and returns an ObjectAnimator that animates over values for a multiple int
parameters setter.
|
static ObjectAnimator |
ofObject(Object target,
String propertyName,
TypeConverter<PointF,?> converter,
Path path)
Constructs and returns an ObjectAnimator that animates a property along a
Path . |
static ObjectAnimator |
ofObject(Object target,
String propertyName,
TypeEvaluator evaluator,
Object... values)
Constructs and returns an ObjectAnimator that animates between Object values.
|
static <T,V,P> ObjectAnimator |
ofObject(T target,
Property<T,P> property,
TypeConverter<V,P> converter,
TypeEvaluator<V> evaluator,
V... values)
Constructs and returns an ObjectAnimator that animates between Object values.
|
static <T,V> ObjectAnimator |
ofObject(T target,
Property<T,V> property,
TypeConverter<PointF,V> converter,
Path path)
Constructs and returns an ObjectAnimator that animates a property along a
Path . |
static <T,V> ObjectAnimator |
ofObject(T target,
Property<T,V> property,
TypeEvaluator<V> evaluator,
V... values)
Constructs and returns an ObjectAnimator that animates between Object values.
|
static ObjectAnimator |
ofPropertyValuesHolder(Object target,
PropertyValuesHolder... values)
Constructs and returns an ObjectAnimator that animates between the sets of values specified
in
PropertyValueHolder objects. |
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.
|
ObjectAnimator |
setDuration(long duration)
Sets the length of the animation.
|
void |
setFloatValues(float... values)
Sets float values that will be animated between.
|
void |
setIntValues(int... values)
Sets int values that will be animated between.
|
void |
setObjectValues(Object... values)
Sets the values to animate between for this animation.
|
void |
setProperty(Property property)
Sets the property that will be animated.
|
void |
setPropertyName(String propertyName)
Sets the name of the property that will be animated.
|
void |
setTarget(Object target)
Sets the target object whose property will be animated by this animation.
|
void |
setupEndValues()
This method tells the object to use appropriate information to extract
ending values for the animation.
|
void |
setupStartValues()
This method tells the object to use appropriate information to extract
starting values for the animation.
|
void |
start()
Starts this animation.
|
String |
toString()
Returns a string representation of the object.
|
addUpdateListener, cancel, canReverse, commitAnimationFrame, doAnimationFrame, end, getAnimatedFraction, getAnimatedValue, getAnimatedValue, getCurrentAnimationsCount, getCurrentPlayTime, getDuration, getDurationScale, getFrameDelay, getInterpolator, getRepeatCount, getRepeatMode, getStartDelay, getTotalDuration, getValues, isRunning, isStarted, ofArgb, ofFloat, ofInt, ofObject, ofPropertyValuesHolder, pause, removeAllUpdateListeners, removeUpdateListener, resume, reverse, setAllowRunningAsynchronously, setCurrentFraction, setCurrentPlayTime, setDurationScale, setEvaluator, setFrameDelay, setInterpolator, setRepeatCount, setRepeatMode, setStartDelay, setValues
addListener, addPauseListener, appendChangingConfigurations, createConstantState, getChangingConfigurations, getListeners, isPaused, removeAllListeners, removeListener, removePauseListener, setChangingConfigurations
public ObjectAnimator()
public void setPropertyName(String propertyName)
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.
propertyName
- The name of the property being animated. Should not be null.public void setProperty(Property property)
setPropertyName(String)
method. Animations should
be set up to use one or the other, not both.property
- The property being animated. Should not be null.public String getPropertyName()
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).
public static ObjectAnimator ofInt(Object target, String propertyName, int... values)
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).target
- The object whose property is to be animated. This object should
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter.propertyName
- The name of the property being animated.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofInt(Object target, String xPropertyName, String yPropertyName, Path path)
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
.target
- The object whose properties are to be animated. This object should
have public methods on it called setNameX()
and
setNameY
, where nameX
and nameY
are the value of xPropertyName
and yPropertyName
parameters, respectively.xPropertyName
- The name of the property for the x coordinate being animated.yPropertyName
- The name of the property for the y coordinate being animated.path
- The Path
to animate values along.path
.public static <T> ObjectAnimator ofInt(T target, Property<T,Integer> property, int... values)
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).target
- The object whose property is to be animated.property
- The property being animated.values
- A set of values that the animation will animate between over time.public static <T> ObjectAnimator ofInt(T target, Property<T,Integer> xProperty, Property<T,Integer> yProperty, Path path)
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
.target
- The object whose properties are to be animated.xProperty
- The property for the x coordinate being animated.yProperty
- The property for the y coordinate being animated.path
- The Path
to animate values along.path
.public static ObjectAnimator ofMultiInt(Object target, String propertyName, int[][] values)
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).target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofMultiInt(Object target, String propertyName, Path path)
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.target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.path
- The Path
to animate values along.path
.@SafeVarargs public static <T> ObjectAnimator ofMultiInt(Object target, String propertyName, TypeConverter<T,int[]> converter, TypeEvaluator<T> evaluator, T... values)
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).
target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.converter
- Converts T objects into int parameters for the multi-value setter.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.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofArgb(Object target, String propertyName, int... values)
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).target
- The object whose property is to be animated. This object should
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter.propertyName
- The name of the property being animated.values
- A set of values that the animation will animate between over time.public static <T> ObjectAnimator ofArgb(T target, Property<T,Integer> property, int... values)
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).target
- The object whose property is to be animated.property
- The property being animated.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofFloat(Object target, String propertyName, float... values)
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).target
- The object whose property is to be animated. This object should
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter.propertyName
- The name of the property being animated.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofFloat(Object target, String xPropertyName, String yPropertyName, Path path)
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
.target
- The object whose properties are to be animated. This object should
have public methods on it called setNameX()
and
setNameY
, where nameX
and nameY
are the value of the xPropertyName
and yPropertyName
parameters, respectively.xPropertyName
- The name of the property for the x coordinate being animated.yPropertyName
- The name of the property for the y coordinate being animated.path
- The Path
to animate values along.path
.public static <T> ObjectAnimator ofFloat(T target, Property<T,Float> property, float... values)
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).target
- The object whose property is to be animated.property
- The property being animated.values
- A set of values that the animation will animate between over time.public static <T> ObjectAnimator ofFloat(T target, Property<T,Float> xProperty, Property<T,Float> yProperty, Path path)
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
.target
- The object whose properties are to be animated.xProperty
- The property for the x coordinate being animated.yProperty
- The property for the y coordinate being animated.path
- The Path
to animate values along.path
.public static ObjectAnimator ofMultiFloat(Object target, String propertyName, float[][] values)
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).target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofMultiFloat(Object target, String propertyName, Path path)
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.target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.path
- The Path
to animate values along.path
.@SafeVarargs public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName, TypeConverter<T,float[]> converter, TypeEvaluator<T> evaluator, T... values)
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).
target
- The object whose property is to be animated. This object may
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter. propertyName
may also
be the case-sensitive complete name of the public setter method.propertyName
- The name of the property being animated or the name of the setter method.converter
- Converts T objects into float parameters for the multi-value setter.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.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofObject(Object target, String propertyName, TypeEvaluator evaluator, Object... values)
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.
target
- The object whose property is to be animated. This object should
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter.propertyName
- The name of the property being animated.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.values
- A set of values that the animation will animate between over time.public static ObjectAnimator ofObject(Object target, String propertyName, TypeConverter<PointF,?> converter, Path path)
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
.target
- The object whose property is to be animated. This object should
have a public method on it called setName()
, where name
is
the value of the propertyName
parameter.propertyName
- The name of the property being animated.converter
- Converts a PointF to the type associated with the setter. May be
null if conversion is unnecessary.path
- The Path
to animate values along.path
.@SafeVarargs public static <T,V> ObjectAnimator ofObject(T target, Property<T,V> property, TypeEvaluator<V> evaluator, V... values)
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.
target
- The object whose property is to be animated.property
- The property being animated.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.values
- A set of values that the animation will animate between over time.@SafeVarargs public static <T,V,P> ObjectAnimator ofObject(T target, Property<T,P> property, TypeConverter<V,P> converter, TypeEvaluator<V> evaluator, V... values)
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.
target
- The object whose property is to be animated.property
- The property being animated.converter
- Converts the animated object to the Property type.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.values
- A set of values that the animation will animate between over time.public static <T,V> ObjectAnimator ofObject(T target, Property<T,V> property, TypeConverter<PointF,V> converter, Path path)
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.
target
- The object whose property is to be animated.property
- The property being animated. Should not be null.converter
- Converts a PointF to the type associated with the setter. May be
null if conversion is unnecessary.path
- The Path
to animate values along.path
.public static ObjectAnimator ofPropertyValuesHolder(Object target, PropertyValuesHolder... values)
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.target
- The object whose property is to be animated. Depending on how the
PropertyValuesObjects were constructed, the target object should either have the Property
objects used to construct the PropertyValuesHolder objects or (if the
PropertyValuesHOlder objects were created with property names) the target object should have
public methods on it called setName()
, where name
is the name of
the property passed in as the propertyName
parameter for each of the
PropertyValuesHolder objects.values
- A set of PropertyValuesHolder objects whose values will be animated between
over time.public void setIntValues(int... values)
ValueAnimator
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.
setIntValues
in class ValueAnimator
values
- A set of values that the animation will animate between over time.public void setFloatValues(float... values)
ValueAnimator
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.
setFloatValues
in class ValueAnimator
values
- A set of values that the animation will animate between over time.public void setObjectValues(Object... values)
ValueAnimator
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.
setObjectValues
in class ValueAnimator
values
- The set of values to animate between.public void setAutoCancel(boolean cancel)
cancel
- Whether future ObjectAnimators with the same target and properties
as this ObjectAnimator will cause this ObjectAnimator to be canceled.public void start()
Animator
Animator.AnimatorListener.onAnimationStart(Animator)
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.
start
in class ValueAnimator
public ObjectAnimator setDuration(long duration)
setDuration
in class ValueAnimator
duration
- The length of the animation, in milliseconds.ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()
.public Object getTarget()
public void setTarget(Object target)
Animator
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.
public void setupStartValues()
Animator
setupStartValues
in class Animator
public void setupEndValues()
Animator
setupEndValues
in class Animator
public ObjectAnimator clone()
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
clone
in class ValueAnimator
Cloneable
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
toString
in class ValueAnimator