Google is committed to advancing racial equity for Black communities. See how.

Animator

abstract class Animator : Cloneable
kotlin.Any
   ↳ androidx.core.animation.Animator

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
abstract

An animation listener receives notifications from an animation.

abstract

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

abstract

Implementors of this interface can add themselves as update listeners to an ValueAnimator instance to receive callbacks on every animation frame, after the current frame's values have been calculated for that ValueAnimator.

Constants
static Long

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

Public constructors

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

Public methods
open Unit

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

open Unit

Adds a pause listener to this animator.

open Unit

Adds a listener to the set of listeners that are sent update events through the life of an animation.

open Unit

Cancels the animation.

open Animator

open Unit
end()

Ends the animation.

abstract Long

Gets the duration of the animation.

open Interpolator?

Returns the timing interpolator that this animation uses.

abstract Long

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

open Long

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

open Boolean

Returns whether this animator is currently in a paused state.

abstract Boolean

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

open Boolean

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

open Unit

Pauses a running animation.

open Unit

Removes all listeners and pauseListeners from this object.

open Unit

Removes all listeners from the set listening to frame updates for this animation.

open Unit

Removes a listener from the set listening to this animation.

open Unit

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

open Unit

Removes a listener from the set listening to frame updates for this animation.

open Unit

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

abstract Animator
setDuration(@IntRange(0) duration: Long)

Sets the duration of the animation.

abstract Unit
setInterpolator(@Nullable value: Interpolator?)

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

abstract Unit
setStartDelay(@IntRange(0) startDelay: Long)

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

open Unit
setTarget(@Nullable target: Any?)

Sets the target object whose property will be animated by this animation.

open Unit

This method tells the object to use appropriate information to extract ending values for the animation.

open Unit

This method tells the object to use appropriate information to extract starting values for the animation.

open Unit

Starts this animation.

Constants

DURATION_INFINITE

static val DURATION_INFINITE: Long

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

Value: -1

Public constructors

<init>

Animator()

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

Public methods

addListener

open fun addListener(@NonNull listener: Animator.AnimatorListener): Unit

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

open fun addPauseListener(@NonNull listener: Animator.AnimatorPauseListener): Unit

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.

addUpdateListener

open fun addUpdateListener(@NonNull listener: Animator.AnimatorUpdateListener): Unit

Adds a listener to the set of listeners that are sent update events through the life of an animation. This method is called on all listeners for every frame of the animation, after the values for the animation have been calculated.

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

cancel

open fun cancel(): Unit

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

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

clone

@NonNull open fun clone(): Animator

end

open fun end(): Unit

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

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

getDuration

abstract fun getDuration(): Long

Gets the duration of the animation.

Return
Long The length of the animation, in milliseconds.

getInterpolator

@Nullable open fun getInterpolator(): Interpolator?

Returns the timing interpolator that this animation uses.

Return
Interpolator? The timing interpolator for this animation.

getStartDelay

abstract fun getStartDelay(): Long

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

Return
Long the number of milliseconds to delay running the animation

getTotalDuration

open fun getTotalDuration(): Long

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

When the animation repeats infinite times, or when any of the child animators does (via ValueAnimator#setRepeatCount(int)} to ValueAnimator#INFINITE), the total duration will be DURATION_INFINITE. Otherwise, the total duration is the sum of start delay and animation running time (i.e. duration of one iteration multiplied by the number of iterations).

Return
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

open fun isPaused(): Boolean

Returns whether this animator is currently in a paused state.

Return
Boolean True if the animator is currently paused, false otherwise.

See Also

isRunning

abstract fun isRunning(): Boolean

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

Return
Boolean Whether the Animator is running.

isStarted

open fun isStarted(): Boolean

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.

Return
Boolean Whether the Animator has been started and not yet ended.

pause

open fun pause(): Unit

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 or has since ended, then the call is ignored. Paused animations can be resumed by calling resume().

See Also