ViewPropertyAnimator
public
class
ViewPropertyAnimator
extends Object
java.lang.Object | |
↳ | android.view.ViewPropertyAnimator |
This class enables automatic and optimized animation of select properties on View objects.
If only one or two properties on a View object are being animated, then using an
ObjectAnimator
is fine; the property setters called by ObjectAnimator
are well equipped to do the right thing to set the property and invalidate the view
appropriately. But if several properties are animated simultaneously, or if you just want a
more convenient syntax to animate a specific property, then ViewPropertyAnimator might be
more well-suited to the task.
This class may provide better performance for several simultaneous animations, because it will optimize invalidate calls to take place only once for several properties instead of each animated property independently causing its own invalidation. Also, the syntax of using this class could be easier to use because the caller need only tell the View object which property to animate, and the value to animate either to or by, and this class handles the details of configuring the underlying Animator class and starting it.
This class is not constructed by the caller, but rather by the View whose properties
it will animate. Calls to View.animate()
will return a reference
to the appropriate ViewPropertyAnimator object for that View.
Summary
Public methods | |
---|---|
ViewPropertyAnimator
|
alpha(float value)
This method will cause the View's |
ViewPropertyAnimator
|
alphaBy(float value)
This method will cause the View's |
void
|
cancel()
Cancels all property animations that are currently running or pending. |
long
|
getDuration()
Returns the current duration of property animations. |
TimeInterpolator
|
getInterpolator()
Returns the timing interpolator that this animation uses. |
long
|
getStartDelay()
Returns the current startDelay of property animations. |
ViewPropertyAnimator
|
rotation(float value)
This method will cause the View's |
ViewPropertyAnimator
|
rotationBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
rotationX(float value)
This method will cause the View's |
ViewPropertyAnimator
|
rotationXBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
rotationY(float value)
This method will cause the View's |
ViewPropertyAnimator
|
rotationYBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
scaleX(float value)
This method will cause the View's |
ViewPropertyAnimator
|
scaleXBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
scaleY(float value)
This method will cause the View's |
ViewPropertyAnimator
|
scaleYBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
setDuration(long duration)
Sets the duration for the underlying animator that animates the requested properties. |
ViewPropertyAnimator
|
setInterpolator(TimeInterpolator interpolator)
Sets the interpolator for the underlying animator that animates the requested properties. |
ViewPropertyAnimator
|
setListener(Animator.AnimatorListener listener)
Sets a listener for events in the underlying Animators that run the property animations. |
ViewPropertyAnimator
|
setStartDelay(long startDelay)
Sets the startDelay for the underlying animator that animates the requested properties. |
ViewPropertyAnimator
|
setUpdateListener(ValueAnimator.AnimatorUpdateListener listener)
Sets a listener for update events in the underlying ValueAnimator that runs the property animations. |
void
|
start()
Starts the currently pending property animations immediately. |
ViewPropertyAnimator
|
translationX(float value)
This method will cause the View's |
ViewPropertyAnimator
|
translationXBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
translationY(float value)
This method will cause the View's |
ViewPropertyAnimator
|
translationYBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
translationZ(float value)
This method will cause the View's |
ViewPropertyAnimator
|
translationZBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
withEndAction(Runnable runnable)
Specifies an action to take place when the next animation ends. |
ViewPropertyAnimator
|
withLayer()
The View associated with this ViewPropertyAnimator will have its
|
ViewPropertyAnimator
|
withStartAction(Runnable runnable)
Specifies an action to take place when the next animation runs. |
ViewPropertyAnimator
|
x(float value)
This method will cause the View's |
ViewPropertyAnimator
|
xBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
y(float value)
This method will cause the View's |
ViewPropertyAnimator
|
yBy(float value)
This method will cause the View's |
ViewPropertyAnimator
|
z(float value)
This method will cause the View's |
ViewPropertyAnimator
|
zBy(float value)
This method will cause the View's |
Inherited methods | |
---|---|
Public methods
alpha
public ViewPropertyAnimator alpha (float value)
This method will cause the View's alpha
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to.
Value is between 0.0f and 1.0f inclusive |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
alphaBy
public ViewPropertyAnimator alphaBy (float value)
This method will cause the View's alpha
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
cancel
public void cancel ()
Cancels all property animations that are currently running or pending.
getDuration
public long getDuration ()
Returns the current duration of property animations. If the duration was set on this object, that value is returned. Otherwise, the default value of the underlying Animator is returned.
Returns | |
---|---|
long |
The duration of animations, in milliseconds. |
See also:
getInterpolator
public TimeInterpolator getInterpolator ()
Returns the timing interpolator that this animation uses.
Returns | |
---|---|
TimeInterpolator |
The timing interpolator for this animation.
This value may be null . |
getStartDelay
public long getStartDelay ()
Returns the current startDelay of property animations. If the startDelay was set on this object, that value is returned. Otherwise, the default value of the underlying Animator is returned.
Returns | |
---|---|
long |
The startDelay of animations, in milliseconds. |
See also:
rotation
public ViewPropertyAnimator rotation (float value)
This method will cause the View's rotation
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
rotationBy
public ViewPropertyAnimator rotationBy (float value)
This method will cause the View's rotation
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
rotationX
public ViewPropertyAnimator rotationX (float value)
This method will cause the View's rotationX
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
rotationXBy
public ViewPropertyAnimator rotationXBy (float value)
This method will cause the View's rotationX
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
rotationY
public ViewPropertyAnimator rotationY (float value)
This method will cause the View's rotationY
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
rotationYBy
public ViewPropertyAnimator rotationYBy (float value)
This method will cause the View's rotationY
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
scaleX
public ViewPropertyAnimator scaleX (float value)
This method will cause the View's scaleX
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
scaleXBy
public ViewPropertyAnimator scaleXBy (float value)
This method will cause the View's scaleX
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
scaleY
public ViewPropertyAnimator scaleY (float value)
This method will cause the View's scaleY
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
scaleYBy
public ViewPropertyAnimator scaleYBy (float value)
This method will cause the View's scaleY
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
setDuration
public ViewPropertyAnimator setDuration (long duration)
Sets the duration for the underlying animator that animates the requested properties. By default, the animator uses the default value for ValueAnimator. Calling this method will cause the declared value to be used instead.
Parameters | |
---|---|
duration |
long : The length of ensuing property animations, in milliseconds. The value
cannot be negative. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
setInterpolator
public ViewPropertyAnimator setInterpolator (TimeInterpolator interpolator)
Sets the interpolator for the underlying animator that animates the requested properties. By default, the animator uses the default interpolator for ValueAnimator. Calling this method will cause the declared object to be used instead.
Parameters | |
---|---|
interpolator |
TimeInterpolator : The TimeInterpolator to be used for ensuing property animations. A value
of null will result in linear interpolation. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
setListener
public ViewPropertyAnimator setListener (Animator.AnimatorListener listener)
Sets a listener for events in the underlying Animators that run the property animations.
Parameters | |
---|---|
listener |
Animator.AnimatorListener : The listener to be called with AnimatorListener events. A value of
null removes any existing listener. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
setStartDelay
public ViewPropertyAnimator setStartDelay (long startDelay)
Sets the startDelay for the underlying animator that animates the requested properties. By default, the animator uses the default value for ValueAnimator. Calling this method will cause the declared value to be used instead.
Parameters | |
---|---|
startDelay |
long : The delay of ensuing property animations, in milliseconds. The value
cannot be negative. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
setUpdateListener
public ViewPropertyAnimator setUpdateListener (ValueAnimator.AnimatorUpdateListener listener)
Sets a listener for update events in the underlying ValueAnimator that runs the property animations. Note that the underlying animator is animating between 0 and 1 (these values are then turned into the actual property values internally by ViewPropertyAnimator). So the animator cannot give information on the current values of the properties being animated by this ViewPropertyAnimator, although the view object itself can be queried to get the current values.
Parameters | |
---|---|
listener |
ValueAnimator.AnimatorUpdateListener : The listener to be called with update events. A value of
null removes any existing listener. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
start
public void start ()
Starts the currently pending property animations immediately. Calling start()
is optional because all animations start automatically at the next opportunity. However,
if the animations are needed to start immediately and synchronously (not at the time when
the next event is processed by the hierarchy, which is when the animations would begin
otherwise), then this method can be used.
translationX
public ViewPropertyAnimator translationX (float value)
This method will cause the View's translationX
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
translationXBy
public ViewPropertyAnimator translationXBy (float value)
This method will cause the View's translationX
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
translationY
public ViewPropertyAnimator translationY (float value)
This method will cause the View's translationY
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
translationYBy
public ViewPropertyAnimator translationYBy (float value)
This method will cause the View's translationY
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
translationZ
public ViewPropertyAnimator translationZ (float value)
This method will cause the View's translationZ
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
translationZBy
public ViewPropertyAnimator translationZBy (float value)
This method will cause the View's translationZ
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
withEndAction
public ViewPropertyAnimator withEndAction (Runnable runnable)
Specifies an action to take place when the next animation ends. The action is only
run if the animation ends normally; if the ViewPropertyAnimator is canceled during
that animation, the runnable will not run.
This method, along with withStartAction(java.lang.Runnable)
, is intended to help facilitate
choreographing ViewPropertyAnimator animations with other animations or actions
in the application.
For example, the following code animates a view to x=200 and then back to 0:
Runnable endAction = new Runnable() { public void run() { view.animate().x(0); } }; view.animate().x(200).withEndAction(endAction);
Parameters | |
---|---|
runnable |
Runnable : The action to run when the next animation ends. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
withLayer
public ViewPropertyAnimator withLayer ()
The View associated with this ViewPropertyAnimator will have its
layer type
set to
View#LAYER_TYPE_HARDWARE
for the duration of the next animation.
As stated in the documentation for View#LAYER_TYPE_HARDWARE
,
the actual type of layer used internally depends on the runtime situation of the
view. If the activity and this view are hardware-accelerated, then the layer will be
accelerated as well. If the activity or the view is not accelerated, then the layer will
effectively be the same as View#LAYER_TYPE_SOFTWARE
.
This state is not persistent, either on the View or on this ViewPropertyAnimator: the
layer type of the View will be restored when the animation ends to what it was when this
method was called, and this setting on ViewPropertyAnimator is only valid for the next
animation. Note that calling this method and then independently setting the layer type of
the View (by a direct call to View#setLayerType(int, android.graphics.Paint)
) will
result in some inconsistency, including having the layer type restored to its pre-withLayer()
value when the animation ends.
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
withStartAction
public ViewPropertyAnimator withStartAction (Runnable runnable)
Specifies an action to take place when the next animation runs. If there is a
startDelay
set on this ViewPropertyAnimator, then the
action will run after that startDelay expires, when the actual animation begins.
This method, along with withEndAction(java.lang.Runnable)
, is intended to help facilitate
choreographing ViewPropertyAnimator animations with other animations or actions
in the application.
Parameters | |
---|---|
runnable |
Runnable : The action to run when the next animation starts. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
x
public ViewPropertyAnimator x (float value)
This method will cause the View's x
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
xBy
public ViewPropertyAnimator xBy (float value)
This method will cause the View's x
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
y
public ViewPropertyAnimator y (float value)
This method will cause the View's y
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
yBy
public ViewPropertyAnimator yBy (float value)
This method will cause the View's y
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
z
public ViewPropertyAnimator z (float value)
This method will cause the View's z
property to be animated to the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The value to be animated to. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also:
zBy
public ViewPropertyAnimator zBy (float value)
This method will cause the View's z
property to be animated by the
specified value. Animations already running on the property will be canceled.
Parameters | |
---|---|
value |
float : The amount to be animated by, as an offset from the current value. |
Returns | |
---|---|
ViewPropertyAnimator |
This object, allowing calls to methods in this class to be chained.
This value cannot be null . |
See also: