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

FloatAnimationSpec

@<Error class: unknown class>
public interface FloatAnimationSpec extends AnimationSpec

Known direct subclasses
FloatSpringSpec

FloatSpringSpec animation uses a spring animation to animate a Float value.

FloatTweenSpec

FloatTweenSpec animates a Float value from any start value to any end value using a provided easing function.


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.

See also
VectorizedAnimationSpec

Summary

Public methods

abstract long
getDurationNanos(
    float initialValue,
    float targetValue,
    float initialVelocity
)

Calculates the duration of an animation.

default float
getEndVelocity(
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

abstract float
getValueFromNanos(
    long playTimeNanos,
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

abstract float
getVelocityFromNanos(
    long playTimeNanos,
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

default @NonNull VectorizedFloatAnimationSpec<@NonNull V>
<V extends AnimationVector> vectorize(
    @NonNull TwoWayConverter<@NonNull Float, @NonNull V> converter
)

Create an VectorizedAnimationSpec that animates AnimationVector from a FloatAnimationSpec.

Public methods

getDurationNanos

abstract long getDurationNanos(
    float initialValue,
    float targetValue,
    float initialVelocity
)

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 initialValue, targetValue values, and initialVelocity.

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

Parameters
float initialValue

start value of the animation

float targetValue

end value of the animation

float initialVelocity

start velocity of the animation

getEndVelocity

default float getEndVelocity(
    float initialValue,
    float targetValue,
    float initialVelocity
)

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
float initialValue

start value of the animation

float targetValue

end value of the animation

float initialVelocity

start velocity of the animation

getValueFromNanos

abstract float getValueFromNanos(
    long playTimeNanos,
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

Parameters
long playTimeNanos

time since the start of the animation

float initialValue

start value of the animation

float targetValue

end value of the animation

float initialVelocity

start velocity of the animation

getVelocityFromNanos

abstract float getVelocityFromNanos(
    long playTimeNanos,
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

Parameters
long playTimeNanos

time since the start of the animation

float initialValue

start value of the animation

float targetValue

end value of the animation

float initialVelocity

start velocity of the animation

vectorize

default @NonNull VectorizedFloatAnimationSpec<@NonNull V> <V extends AnimationVector> vectorize(
    @NonNull TwoWayConverter<@NonNull Float, @NonNull V> converter
)

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