Skip to content

Most visited

Recently visited

navigation

Animator

public abstract class Animator
extends Object implements Cloneable

java.lang.Object
   ↳ android.animation.Animator
Known Direct Subclasses
Known Indirect Subclasses


This is the superclass for classes which provide basic support for animations which can be started, ended, and have AnimatorListeners added to them.

Summary

Nested classes

interface Animator.AnimatorListener

An animation listener receives notifications from an animation. 

interface Animator.AnimatorPauseListener

A pause listener receives notifications from an animation when the animation is paused or resumed

Constants

long DURATION_INFINITE

The value used to indicate infinite duration (e.g.

Public constructors

Animator()

Public methods

void addListener(Animator.AnimatorListener listener)

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

void addPauseListener(Animator.AnimatorPauseListener listener)

Adds a pause listener to this animator.

void cancel()

Cancels the animation.

Animator clone()

Creates and returns a copy of this object.

void end()

Ends the animation.

abstract long getDuration()

Gets the duration of the animation.

TimeInterpolator getInterpolator()

Returns the timing interpolator that this animation uses.

ArrayList<Animator.AnimatorListener> getListeners()

Gets the set of Animator.AnimatorListener objects that are currently listening for events on this Animator object.

abstract long getStartDelay()

The amount of time, in milliseconds, to delay processing the animation after start() is called.

long getTotalDuration()

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating.

boolean isPaused()

Returns whether this animator is currently in a paused state.

abstract boolean isRunning()

Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).

boolean isStarted()

Returns whether this Animator has been started and not yet ended.

void pause()

Pauses a running animation.

void removeAllListeners()

Removes all listeners and pauseListeners from this object.

void removeListener(Animator.AnimatorListener listener)

Removes a listener from the set listening to this animation.

void removePauseListener(Animator.AnimatorPauseListener listener)

Removes a pause listener from the set listening to this animation.

void resume()

Resumes a paused animation, causing the animator to pick up where it left off when it was paused.

abstract Animator setDuration(long duration)

Sets the duration of the animation.

abstract void setInterpolator(TimeInterpolator value)

The time interpolator used in calculating the elapsed fraction of the animation.

abstract void setStartDelay(long startDelay)

The amount of time, in milliseconds, to delay processing the animation after start() is called.

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.

Inherited methods

From class java.lang.Object

Constants

DURATION_INFINITE

Added in API level 24
long DURATION_INFINITE

The value used to indicate infinite duration (e.g. when Animators repeat infinitely).

Constant Value: -1 (0xffffffffffffffff)

Public constructors

Animator

Added in API level 11
Animator ()

Public methods

addListener

Added in API level 11
void addListener (Animator.AnimatorListener listener)

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Parameters
listener Animator.AnimatorListener: the listener to be added to the current set of listeners for this animation.

addPauseListener

Added in API level 19
void addPauseListener (Animator.AnimatorPauseListener listener)

Adds a pause listener to this animator.

Parameters
listener Animator.AnimatorPauseListener: the listener to be added to the current set of pause listeners for this animation.

cancel

Added in API level 11
void cancel ()

Cancels the animation. Unlike end(), cancel() causes the animation to stop in its tracks, sending an onAnimationCancel(Animator) to its listeners, followed by an onAnimationEnd(Animator) message.

This method must be called on the thread that is running the animation.

clone

Added in API level 11
Animator clone ()

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be 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.

Returns
Animator a clone of this instance.

end

Added in API level 11
void end ()

Ends the animation. This causes the animation to assign the end value of the property being animated, then calling the onAnimationEnd(Animator) method on its listeners.

This method must be called on the thread that is running the animation.

getDuration

Added in API level 11
long getDuration ()

Gets the duration of the animation.

Returns
long The length of the animation, in milliseconds.

getInterpolator

Added in API level 18
TimeInterpolator getInterpolator ()

Returns the timing interpolator that this animation uses.

Returns
TimeInterpolator The timing interpolator for this animation.

getListeners

Added in API level 11
ArrayList<Animator.AnimatorListener> getListeners ()

Gets the set of Animator.AnimatorListener objects that are currently listening for events on this Animator object.

Returns
ArrayList<Animator.AnimatorListener> ArrayList The set of listeners.

getStartDelay

Added in API level 11
long getStartDelay ()

The amount of time, in milliseconds, to delay processing the animation after start() is called.

Returns
long the number of milliseconds to delay running the animation

getTotalDuration

Added in API level 24
long getTotalDuration ()

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. Return DURATION_INFINITE if the duration is infinite.

Returns
long Total time an animation takes to finish, starting from the time start() is called. DURATION_INFINITE will be returned if the animation or any child animation repeats infinite times.

isPaused

Added in API level 19
boolean isPaused ()

Returns whether this animator is currently in a paused state.

Returns
boolean True if the animator is currently paused, false otherwise.

See also:

isRunning

Added in API level 11
boolean isRunning ()

Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).

Returns
boolean Whether the Animator is running.

isStarted

Added in API level 14
boolean isStarted ()

Returns whether this Animator has been started and not yet ended. For reusable Animators (which most Animators are, apart from the one-shot animator produced by createCircularReveal()), this state is a superset of isRunning(), because an Animator with a nonzero startDelay will return true for isStarted() during the delay phase, whereas isRunning() will return true only after the delay phase is complete. Non-reusable animators will always return true after they have been started, because they cannot return to a non-started state.

Returns
boolean Whether the Animator has been started and not yet ended.

pause

Added in API level 19
void pause ()

Pauses a running animation. This method should only be called on the same thread on which the animation was started. If the animation has not yet been started or has since ended, then the call is ignored. Paused animations can be resumed by calling resume().

See also:

removeAllListeners

Added in API level 11
void removeAllListeners ()

Removes all listeners and pauseListeners from this object.

removeListener

Added in API level 11
void removeListener (Animator.AnimatorListener listener)

Removes a listener from the set listening to this animation.

Parameters
listener Animator.AnimatorListener: the listener to be removed from the current set of listeners for this animation.

removePauseListener

Added in API level 19
void removePauseListener (Animator.AnimatorPauseListener listener)

Removes a pause listener from the set listening to this animation.

Parameters
listener Animator.AnimatorPauseListener: the listener to be removed from the current set of pause listeners for this animation.

resume

Added in API level 19
void resume ()

Resumes a paused animation, causing the animator to pick up where it left off when it was paused. This method should only be called on the same thread on which the animation was started. Calls to resume() on an animator that is not currently paused will be ignored.

See also:

setDuration

Added in API level 11
Animator setDuration (long duration)

Sets the duration of the animation.

Parameters
duration long: The length of the animation, in milliseconds.
Returns
Animator

setInterpolator

Added in API level 11
void setInterpolator (TimeInterpolator value)

The time interpolator used in calculating the elapsed fraction of the animation. The interpolator determines whether the animation runs with linear or non-linear motion, such as acceleration and deceleration. The default value is AccelerateDecelerateInterpolator.

Parameters
value TimeInterpolator: the interpolator to be used by this animation

setStartDelay

Added in API level 11
void setStartDelay (long startDelay)

The amount of time, in milliseconds, to delay processing the animation after start() is called.

Parameters
startDelay long: The amount of the delay, in milliseconds

setTarget

Added in API level 11
void setTarget (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.

Parameters
target Object: The object being animated

setupEndValues

Added in API level 11
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

Added in API level 11
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

Added in API level 11
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(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.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.