{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Animation

@<Error class: unknown class>
public interface Animation<T extends Object, V extends AnimationVector>

Known direct subclasses
DecayAnimation

DecayAnimation is an animation that slows down from initialVelocityVector as time goes on.

TargetBasedAnimation

This is a convenient animation wrapper class that works for all target based animations, i.e. animations that has a pre-defined end value, unlike decay.


This interface provides a convenient way to query from an VectorizedAnimationSpec or FloatDecayAnimationSpec: It spares the need to pass the starting conditions and in some cases ending condition for each value or velocity query, and instead only requires the play time to be passed for such queries.

The implementation of this interface should cache the starting conditions and ending conditions of animations as needed.

Note: Animation does not track the lifecycle of an animation. It merely reacts to play time change and returns the new value/velocity as a result. It can be used as a building block for more lifecycle aware animations. In contrast, Animatable and Transition are stateful and manage their own lifecycles.

See also
Animatable
updateTransition

Summary

Public methods

abstract long

This amount of time in nanoseconds that the animation will run before it finishes

abstract @NonNull T

This is the value that the Animation will reach when it finishes uninterrupted.

abstract @NonNull TwoWayConverter<@NonNull T, @NonNull V>

The TwoWayConverter that will be used to convert value/velocity from any arbitrary data type to AnimationVector.

abstract @NonNull T
getValueFromNanos(long playTimeNanos)

Returns the value of the animation at the given play time.

abstract @NonNull V
getVelocityVectorFromNanos(long playTimeNanos)

Returns the velocity (in AnimationVector form) of the animation at the given play time.

default boolean
isFinishedFromNanos(long playTimeNanos)

Returns whether the animation is finished at the given play time.

abstract boolean

Whether or not the Animation represents an infinite animation.

Extension functions

default final @NonNull T
<T extends Object, V extends AnimationVector> AnimationKt.getVelocityFromNanos(
    @NonNull Animation<@NonNull T, @NonNull V> receiver,
    long playTimeNanos
)

Returns the velocity of the animation at the given play time.

Public methods

getDurationNanos

abstract long getDurationNanos()

This amount of time in nanoseconds that the animation will run before it finishes

getTargetValue

abstract @NonNullgetTargetValue()

This is the value that the Animation will reach when it finishes uninterrupted.

getTypeConverter

abstract @NonNull TwoWayConverter<@NonNull T, @NonNull V> getTypeConverter()

The TwoWayConverter that will be used to convert value/velocity from any arbitrary data type to AnimationVector. This makes it possible to animate different dimensions of the data object independently (e.g. x/y dimensions of the position data).

getValueFromNanos

abstract @NonNullgetValueFromNanos(long playTimeNanos)

Returns the value of the animation at the given play time.

Parameters
long playTimeNanos

the play time that is used to determine the value of the animation.

getVelocityVectorFromNanos

abstract @NonNullgetVelocityVectorFromNanos(long playTimeNanos)

Returns the velocity (in AnimationVector form) of the animation at the given play time.

Parameters
long playTimeNanos

the play time that is used to calculate the velocity of the animation.

isFinishedFromNanos

default boolean isFinishedFromNanos(long playTimeNanos)

Returns whether the animation is finished at the given play time.

Parameters
long playTimeNanos

the play time used to determine whether the animation is finished.

isInfinite

abstract boolean isInfinite()

Whether or not the Animation represents an infinite animation. That is, one that will not finish by itself, one that needs an external action to stop. For examples, an indeterminate progress bar, which will only stop when it is removed from the composition.

Extension functions

AnimationKt.getVelocityFromNanos

default final @NonNull T <T extends Object, V extends AnimationVector> AnimationKt.getVelocityFromNanos(
    @NonNull Animation<@NonNull T, @NonNull V> receiver,
    long playTimeNanos
)

Returns the velocity of the animation at the given play time.

Parameters
long playTimeNanos

the play time that is used to calculate the velocity of the animation.