DynamicAnimation
abstract class DynamicAnimation<T : DynamicAnimation<T>!> : AnimationFrameCallback
kotlin.Any | |
↳ | androidx.dynamicanimation.animation.DynamicAnimation |
This class is the base class of physics-based animations. It manages the animation's lifecycle such as start()
and cancel()
. This base class also handles the common setup for all the subclass animations. For example, DynamicAnimation supports adding OnAnimationEndListener
and OnAnimationUpdateListener
so that the important animation events can be observed through the callbacks. The start conditions for any subclass of DynamicAnimation can be set using setStartValue(float)
and setStartVelocity(float)
.
Summary
Nested classes | |
---|---|
abstract |
An animation listener that receives end notifications from an animation. |
abstract |
Implementors of this interface can add themselves as update listeners to an |
abstract |
ViewProperty holds the access of a property of a |
Constants | |
---|---|
static Float |
The minimum visible change in alpha that can be visible to users. |
static Float |
The minimum visible change in pixels that can be visible to users. |
static Float |
The minimum visible change in degrees that can be visible to users. |
static Float |
The minimum visible change in scale that can be visible to users. |
Public methods | |
---|---|
open T |
Adds an end listener to the animation for receiving onAnimationEnd callbacks. |
open T |
Adds an update listener to the animation for receiving per-frame animation update callbacks. |
open Unit |
cancel() Cancels the on-going animation. |
open Float |
Returns the minimum change in the animation property that could be visibly different to users. |
open Boolean |
Returns whether the animation is currently running. |
open Unit |
Removes the end listener from the animation, so as to stop receiving animation end callbacks. |
open Unit |
Removes the update listener from the animation, so as to stop receiving animation update callbacks. |
open T |
setMaxValue(max: Float) Sets the max value of the animation. |
open T |
setMinValue(min: Float) Sets the min value of the animation. |
open T |
setMinimumVisibleChange(@FloatRange(0.0, false) minimumVisibleChange: Float) This method sets the minimal change of animation value that is visible to users, which helps determine a reasonable threshold for the animation's termination condition. |
open T |
setStartValue(startValue: Float) Sets the start value of the animation. |
open T |
setStartVelocity(startVelocity: Float) Start velocity of the animation. |
open Unit |
start() Starts an animation. |
Properties | |
---|---|
static DynamicAnimation.ViewProperty! |
View's alpha property. |
static DynamicAnimation.ViewProperty! |
View's rotation property. |
static DynamicAnimation.ViewProperty! |
View's rotationX property. |
static DynamicAnimation.ViewProperty! |
View's rotationY property. |
static DynamicAnimation.ViewProperty! |
View's scaleX property. |
static DynamicAnimation.ViewProperty! |
View's scaleY property. |
static DynamicAnimation.ViewProperty! |
View's scrollX property. |
static DynamicAnimation.ViewProperty! |
View's scrollY property. |
static DynamicAnimation.ViewProperty! |
View's translationX property. |
static DynamicAnimation.ViewProperty! |
View's translationY property. |
static DynamicAnimation.ViewProperty! |
View's translationZ property. |
static DynamicAnimation.ViewProperty! |
View's x property. |
static DynamicAnimation.ViewProperty! |
View's y property. |
static DynamicAnimation.ViewProperty! |
View's z property. |
Constants
MIN_VISIBLE_CHANGE_ALPHA
static val MIN_VISIBLE_CHANGE_ALPHA: Float
The minimum visible change in alpha that can be visible to users.
Value: 1f / 256f
MIN_VISIBLE_CHANGE_PIXELS
static val MIN_VISIBLE_CHANGE_PIXELS: Float
The minimum visible change in pixels that can be visible to users.
Value: 1f
MIN_VISIBLE_CHANGE_ROTATION_DEGREES
static val MIN_VISIBLE_CHANGE_ROTATION_DEGREES: Float
The minimum visible change in degrees that can be visible to users.
Value: 1f / 10f
MIN_VISIBLE_CHANGE_SCALE
static val MIN_VISIBLE_CHANGE_SCALE: Float
The minimum visible change in scale that can be visible to users.
Value: 1f / 500f
Public methods
addEndListener
open fun addEndListener(listener: DynamicAnimation.OnAnimationEndListener!): T
Adds an end listener to the animation for receiving onAnimationEnd callbacks. If the listener is null
or has already been added to the list of listeners for the animation, no op.
Parameters | |
---|---|
listener |
DynamicAnimation.OnAnimationEndListener!: the listener to be added |
Return | |
---|---|
T |
the animation to which the listener is added |
addUpdateListener
open fun addUpdateListener(listener: DynamicAnimation.OnAnimationUpdateListener!): T
Adds an update listener to the animation for receiving per-frame animation update callbacks. If the listener is null
or has already been added to the list of listeners for the animation, no op.
Note that update listener should only be added before the start of the animation.
Parameters | |
---|---|
listener |
DynamicAnimation.OnAnimationUpdateListener!: the listener to be added |
Return | |
---|---|
T |
the animation to which the listener is added |
Exceptions | |
---|---|
UnsupportedOperationException |
if the update listener is added after the animation has started |
cancel
@MainThread open fun cancel(): Unit
Cancels the on-going animation. If the animation hasn't started, no op. Note that this method should only be called on main thread.
Exceptions | |
---|---|
AndroidRuntimeException |
if this method is not called on the main thread |
getMinimumVisibleChange
open fun getMinimumVisibleChange(): Float
Returns the minimum change in the animation property that could be visibly different to users.
Return | |
---|---|
Float |
minimum change in property value that is visible to users |
isRunning
open fun isRunning(): Boolean
Returns whether the animation is currently running.
Return | |
---|---|
Boolean |
true if the animation is currently running, false otherwise |
removeEndListener
open fun removeEndListener(listener: DynamicAnimation.OnAnimationEndListener!): Unit
Removes the end listener from the animation, so as to stop receiving animation end callbacks.
Parameters | |
---|---|
listener |
DynamicAnimation.OnAnimationEndListener!: the listener to be removed |
removeUpdateListener
open fun removeUpdateListener(listener: DynamicAnimation.OnAnimationUpdateListener!): Unit
Removes the update listener from the animation, so as to stop receiving animation update callbacks.
Parameters | |
---|---|
listener |
DynamicAnimation.OnAnimationUpdateListener!: the listener to be removed |
setMaxValue
open fun setMaxValue(max: Float): T
Sets the max value of the animation. Animations will not animate beyond their max value. Whether or not animation will come to an end when max value is reached is dependent on the child animation's implementation.
Parameters | |
---|---|
max |
Float: maximum value of the property to be animated |
Return | |
---|---|
T |
the Animation whose max value is being set |
setMinValue
open fun setMinValue(min: Float): T
Sets the min value of the animation. Animations will not animate beyond their min value. Whether or not animation will come to an end when min value is reached is dependent on the child animation's implementation.
Parameters | |
---|---|
min |
Float: minimum value of the property to be animated |
Return | |
---|---|
T |
the Animation whose min value is being set |
setMinimumVisibleChange
open fun setMinimumVisibleChange(@FloatRange(0.0, false) minimumVisibleChange: Float): T
This method sets the minimal change of animation value that is visible to users, which helps determine a reasonable threshold for the animation's termination condition. It is critical to set the minimal visible change fo