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

FloatAnimationSpec

interface FloatAnimationSpec : AnimationSpec<Float>
androidx.animation.FloatAnimationSpec

FloatAnimationSpec interface is similar to VectorizedAnimationSpec, except it deals exclusively with floats.

Like VectorizedAnimationSpec, FloatAnimationSpec is entirely stateless as well. It requires start/end values and start velocity to be passed in for the query of velocity and value of the animation. The FloatAnimationSpec itself stores only the animation configuration (such as the delay, duration and easing curve for FloatTweenSpec, or spring constants for FloatSpringSpec.

A FloatAnimationSpec can be converted to an VectorizedAnimationSpec using vectorize.

Summary

Public methods
abstract Long
getDurationMillis(start: Float, end: Float, startVelocity: Float)

Calculates the duration of an animation.

open Float
getEndVelocity(start: Float, end: Float, startVelocity: Float)

Calculates the end velocity of the animation with the provided start/end values, and start velocity.

abstract Float
getValue(playTime: Long, start: Float, end: Float, startVelocity: Float)

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

abstract Float
getVelocity(playTime: Long, start: Float, end: Float, startVelocity: Float)

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

open VectorizedFloatAnimationSpec<V>
vectorize(converter: TwoWayConverter<Float, V>)

Create an VectorizedAnimationSpec that animates AnimationVector from a FloatAnimationSpec.

Public methods

getDurationMillis

abstract fun getDurationMillis(
    start: Float,
    end: Float,
    startVelocity: Float
): Long

Calculates the duration of an animation. For duration-based animations, this will return the pre-defined duration. For physics-based animations, the duration will be estimated based on the physics configuration (such as spring stiffness, damping ratio, visibility threshold) as well as the start, end values, and startVelocity.

Note: this may be a computation that is expensive - especially with spring based animations

Parameters
start: Float start value of the animation
end: Float end value of the animation
startVelocity: Float start velocity of the animation

getEndVelocity

open fun getEndVelocity(
    start: Float,
    end: Float,
    startVelocity: Float
): Float

Calculates the end velocity of the animation with the provided start/end values, and start velocity. For duration-based animations, end velocity will be the velocity of the animation at the duration time. This is also the default assumption. However, for spring animations, the transient trailing velocity will be snapped to zero.

Parameters
start: Float start value of the animation
end: Float end value of the animation
startVelocity: Float start velocity of the animation

getValue

abstract fun getValue(
    playTime: Long,
    start: Float,
    end: Float,
    startVelocity: Float
): Float

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTime: Long time since the start of the animation
start: Float start value of the animation
end: Float end value of the animation
startVelocity: Float start velocity of the animation

getVelocity

abstract fun getVelocity(
    playTime: Long,
    start: Float,
    end: Float,
    startVelocity: Float
): Float

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTime: Long time since the start of the animation
start: Float start value of the animation
end: Float end value of the animation
startVelocity: Float start velocity of the animation

vectorize

open fun <V : AnimationVector> vectorize(converter: TwoWayConverter<Float, V>): VectorizedFloatAnimationSpec<V>

Create an VectorizedAnimationSpec that animates AnimationVector from a FloatAnimationSpec. Every dimension of the AnimationVector will be animated using the given FloatAnimationSpec.