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

TargetBasedAnimation

class TargetBasedAnimation<T, V : AnimationVector> : Animation<T, V>
kotlin.Any
   ↳ androidx.animation.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.

It assumes that the starting value and velocity, as well as ending value do not change throughout the animation, and cache these values. This caching enables much more convenient query for animation value and velocity (where only playtime needs to be passed into the methods).

Note: When interruptions happen to the TargetBasedAnimation, a new instance should be created that use the current value and velocity as the starting conditions. This type of interruption handling is the default behavior for both AnimatedValue and TransitionAnimation. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Summary

Public constructors
<init>(animationSpec: AnimationSpec<V>, startValue: T, endValue: T, startVelocity: T, converter: TwoWayConverter<T, V>)

Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.

<init>(animationSpec: AnimationSpec<V>, startValue: T, endValue: T, startVelocityVector: V, converter: TwoWayConverter<T, V>)

This is a convenient animation wrapper class that works for all target based animations, i.

Public methods
T
getValue(playTime: Long)

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

V

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

Inherited functions
Inherited extension functions
From androidx.animation
T
Animation<T, V>.getVelocity(playTime: Long)

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

Properties
TwoWayConverter<T, V>

the TwoWayConverter that is used to convert animation type T from/to V

Long

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

T

the end value of the animation

Public constructors

<init>

TargetBasedAnimation(
    animationSpec: AnimationSpec<V>,
    startValue: T,
    endValue: T,
    startVelocity: T,
    converter: TwoWayConverter<T, V>)

Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.

The resulting Animation assumes that the start value and velocity, as well as end value do not change throughout the animation, and cache these values. This caching enables much more convenient query for animation value and velocity (where only playtime needs to be passed into the methods).

Note: When interruptions happen to the TargetBasedAnimation, a new instance should be created that use the current value and velocity as the starting conditions. This type of interruption handling is the default behavior for both AnimatedValue and TransitionAnimation. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Parameters
animationSpec: AnimationSpec<V> the AnimationSpec that will be used to calculate value/velocity
startValue: T the start value of the animation
endValue: T the end value of the animation
startVelocity: T the start velocity (of type T of the animation
converter: TwoWayConverter<T, V> the TwoWayConverter that is used to convert animation type T from/to V

<init>

TargetBasedAnimation(
    animationSpec: AnimationSpec<V>,
    startValue: T,
    endValue: T,
    startVelocityVector: V,
    converter: TwoWayConverter<T, V>)

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.

It assumes that the starting value and velocity, as well as ending value do not change throughout the animation, and cache these values. This caching enables much more convenient query for animation value and velocity (where only playtime needs to be passed into the methods).

Note: When interruptions happen to the TargetBasedAnimation, a new instance should be created that use the current value and velocity as the starting conditions. This type of interruption handling is the default behavior for both AnimatedValue and TransitionAnimation. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Parameters
animationSpec: AnimationSpec<V> the AnimationSpec that will be used to calculate value/velocity
startValue: T the start value of the animation
endValue: T the end value of the animation
startVelocityVector: V the start velocity of the animation in the form of AnimationVector
converter: TwoWayConverter<T, V> the TwoWayConverter that is used to convert animation type T from/to V

Public methods

getValue

fun getValue(playTime: Long): T

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

Parameters
playTime: Long the play time that is used to determine the value of the animation.

getVelocityVector

fun getVelocityVector(playTime: Long): V

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

Parameters
playTime: Long the play time that is used to calculate the velocity of the animation.

Properties

converter

val converter: TwoWayConverter<T, V>

the TwoWayConverter that is used to convert animation type T from/to V

durationMillis

val durationMillis: Long

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

endValue

val endValue: T

the end value of the animation