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

FloatTweenSpec

public final class FloatTweenSpec implements FloatAnimationSpec


FloatTweenSpec animates a Float value from any start value to any end value using a provided easing function. The animation will finish within the duration time. Unless a delay is specified, the animation will start right away.

Summary

Public constructors

FloatTweenSpec(int duration, int delay, @NonNull Easing easing)

Public methods

final int

the amount of time the animation will wait before it starts running.

final int

the amount of time (in milliseconds) the animation will take to finish.

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

Calculates the duration of an animation.

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.

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.

Inherited methods

From androidx.compose.animation.core.FloatAnimationSpec
float
getEndVelocity(
    float initialValue,
    float targetValue,
    float initialVelocity
)

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

@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 constructors

FloatTweenSpec

public FloatTweenSpec(int duration, int delay, @NonNull Easing easing)
Parameters
int duration

the amount of time (in milliseconds) the animation will take to finish. Defaults to DefaultDuration

int delay

the amount of time the animation will wait before it starts running. Defaults to 0.

@NonNull Easing easing

the easing function that will be used to interoplate between the start and end value of the animation. Defaults to FastOutSlowInEasing.

Public methods

getDelay

public final int getDelay()

the amount of time the animation will wait before it starts running. Defaults to 0.

getDuration

public final int getDuration()

the amount of time (in milliseconds) the animation will take to finish. Defaults to DefaultDuration

getDurationNanos

public 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

getValueFromNanos

public 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

public 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