Animator
abstract class Animator : Cloneable
kotlin.Any | |
↳ | android.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 |
Constants | |
---|---|
static Long |
The value used to indicate infinite duration (e.g. when Animators repeat infinitely). |
Public constructors | |
---|---|
Animator() |
Public methods | |
---|---|
open Unit |
addListener(listener: Animator.AnimatorListener!) 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 |
addPauseListener(listener: Animator.AnimatorPauseListener!) Adds a pause listener to this animator. |
open Unit |
cancel() Cancels the animation. |
open Animator |
clone() |
open Unit |
end() Ends the animation. |
abstract Long |
Gets the duration of the animation. |
open TimeInterpolator! |
Returns the timing interpolator that this animation uses. |
open ArrayList<Animator.AnimatorListener!>! |
Gets the set of |
abstract Long |
The amount of time, in milliseconds, to delay processing the animation after |
open Long |
Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. |
open Boolean |
isPaused() 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 |
pause() Pauses a running animation. |
open Unit |
Removes all |
open Unit |
removeListener(listener: Animator.AnimatorListener!) Removes a listener from the set listening to this animation. |
open Unit |
removePauseListener(listener: Animator.AnimatorPauseListener!) Removes a pause listener from the set listening to this animation. |
open Unit |
resume() Resumes a paused animation, causing the animator to pick up where it left off when it was paused. |
abstract Animator! |
setDuration(duration: Long) Sets the duration of the animation. |
abstract Unit |
setInterpolator(value: TimeInterpolator!) The time interpolator used in calculating the elapsed fraction of the animation. |
abstract Unit |
setStartDelay(startDelay: Long) The amount of time, in milliseconds, to delay processing the animation after |
open Unit |
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 |
start() 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: -1L
Public constructors
Animator
Animator()
Public methods
addListener
open fun addListener(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(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. |
cancel
open fun cancel(): Unit
Cancels the animation. Unlike end()
, cancel()
causes the animation to stop in its tracks, sending an android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)
to its listeners, followed by an android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)
message.
This method must be called on the thread that is running the animation.
clone
open fun clone(): Animator
Return | |
---|---|
Animator |
a clone of this instance. |
Exceptions | |
---|---|
java.lang.CloneNotSupportedException |
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned. |
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 android.animation.Animator.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
open fun getInterpolator(): TimeInterpolator!
Returns the timing interpolator that this animation uses.
Return | |
---|---|
TimeInterpolator! |
The timing interpolator for this animation. |
getListeners
open fun getListeners(): ArrayList<Animator.AnimatorListener!>!
Gets the set of android.animation.Animator.AnimatorListener
objects that are currently listening for events on this Animator
object.
Return | |
---|---|
ArrayList<Animator.AnimatorListener!>! |
ArrayList The set of listeners. |
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. Return DURATION_INFINITE
if the duration is infinite.
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. |
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 started
or has since ended, then the call is ignored. Paused animations can be resumed by calling resume()
.
removeAllListeners
open fun removeAllListeners(): Unit
Removes all listeners
and pauseListeners
from this object.
removeListener
open fun removeListener(listener: Animator.AnimatorListener!): Unit
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
open fun removePauseListener(listener: Animator.AnimatorPauseListener!): Unit
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
open fun resume(): Unit
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.
setDuration
abstract fun setDuration(duration: Long): Animator!
Sets the duration of the animation.
Parameters | |
---|---|
duration |
Long: The length of the animation, in milliseconds. |
setInterpolator
abstract fun setInterpolator(value: TimeInterpolator!): Unit
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 android.view.animation.AccelerateDecelerateInterpolator
.
Parameters | |
---|---|
value |
TimeInterpolator!: the interpolator to be used by this animation |
setStartDelay
abstract fun setStartDelay(startDelay: Long): Unit
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
open fun setTarget(target: Any?): Unit
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 |
Any?: The object being animated This value may be null . |
setupEndValues
open fun setupEndValues(): Unit
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
open fun setupStartValues(): Unit
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
open fun start(): Unit
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 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.