Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

ValueAnimator

open class ValueAnimator : Animator, AnimationFrameCallback
kotlin.Any
   ↳ androidx.core.animation.Animator
   ↳ androidx.core.animation.ValueAnimator

This class provides a simple timing engine for running animations which calculate animated values and set them on target objects.

There is a single timing pulse that all animations use. It runs in a custom handler to ensure that property changes happen on the UI thread.

By default, ValueAnimator uses non-linear time interpolation, via the AccelerateDecelerateInterpolator class, which accelerates into and decelerates out of an animation. This behavior can be changed by calling ValueAnimator#setInterpolator(Interpolator).

Animators can be created from either code or resource files. Here is an example of a ValueAnimator resource file:

ValueAnimator also supports the use of a combination of PropertyValuesHolder and Keyframe resource tags to create a multi-step animation. Note that you can specify explicit fractional values (from 0 to 1) for each keyframe to determine when, in the overall duration, the animation should arrive at that value. Alternatively, you can leave the fractions off and the keyframes will be equally distributed within the total duration:

Summary

Constants
static Int

This value used used with the setRepeatCount(int) property to repeat the animation indefinitely.

static Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

static Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

Inherited constants
Public constructors

Creates a new ValueAnimator object.

Public methods
open static Boolean

Returns whether animators are currently enabled, system-wide.

open Unit

open ValueAnimator

open Unit
end()

open Float

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

open Any

The most recent value calculated by this ValueAnimator when there is just one property being animated.

open Any?
getAnimatedValue(@NonNull propertyName: String)

The most recent value calculated by this ValueAnimator for propertyName.

open Long

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started.

open Long

Gets the length of the animation.

open static Long

The amount of time, in milliseconds, between each frame of the animation.

open Interpolator?

Returns the timing interpolator that this ValueAnimator uses.

open String

Returns the name of this animator for debugging purposes.

open Int

Defines how many times the animation should repeat.

open Int

Defines what this animation should do when it reaches the end.

open Long

The amount of time, in milliseconds, to delay starting the animation after start() is called.

open Long

open Array<PropertyValuesHolder!>

Returns the values that this ValueAnimator animates between.

open Boolean

open Boolean

open static ValueAnimator
ofArgb(@NonNull vararg values: Int)

Constructs and returns a ValueAnimator that animates between color values.

open static ValueAnimator
ofFloat(@NonNull vararg values: Float)

Constructs and returns a ValueAnimator that animates between float values.

open static ValueAnimator
ofInt(@NonNull vararg values: Int)

Constructs and returns a ValueAnimator that animates between int values.

open static ValueAnimator
ofObject(@NonNull evaluator: TypeEvaluator<Any!>, @NonNull vararg values: Any!)

Constructs and returns a ValueAnimator that animates between Object values.

open static ValueAnimator
ofPropertyValuesHolder(@NonNull vararg values: PropertyValuesHolder!)

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

open Unit

open Unit

open Unit

Plays the ValueAnimator in reverse.

open Unit

Sets the position of the animation to the specified fraction.

open Unit

Sets the position of the animation to the specified point in time.

open ValueAnimator
setDuration(duration: Long)

Sets the length of the animation.

open Unit
setEvaluator(@NonNull value: TypeEvaluator<Any!>)

The type evaluator to be used when calculating the animated values of this animation.

open Unit
setFloatValues(@NonNull vararg values: Float)

Sets float values that will be animated between.

open static Unit
setFrameDelay(frameDelay: Long)

The amount of time, in milliseconds, between each frame of the animation.

open Unit
setIntValues(@NonNull vararg values: Int)

Sets int values that will be animated between.

open Unit
setInterpolator(@Nullable value: Interpolator?)

The interpolator used in calculating the elapsed fraction of this animation.

open Unit
setNameForTrace(@NonNull animationName: String)

Sets a name for the animation to show up in the systrace.

open Unit
setObjectValues(@NonNull vararg values: Any!)

Sets the values to animate between for this animation.

open Unit

Sets how many times the animation should be repeated.

open Unit

Defines what this animation should do when it reaches the end.

open Unit
setStartDelay(startDelay: Long)

The amount of time, in milliseconds, to delay starting the animation after start() is called.

open Unit
setValues(@NonNull vararg values: PropertyValuesHolder!)

Sets the values, per property, being animated between.

open Unit

open String

Inherited functions

Constants

INFINITE

static val INFINITE: Int

This value used used with the setRepeatCount(int) property to repeat the animation indefinitely.

Value: -1

RESTART

static val RESTART: Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

Value: 1

REVERSE

static val REVERSE: Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

Value: 2

Public constructors

<init>

ValueAnimator()

Creates a new ValueAnimator object. This default constructor is primarily for use internally; the factory methods which take parameters are more generally useful.

Public methods

areAnimatorsEnabled

open static fun areAnimatorsEnabled(): Boolean

Returns whether animators are currently enabled, system-wide. By default, all animators are enabled. This can change if either the user sets a Developer Option to set the animator duration scale to 0 or by Battery Savery mode being enabled (which disables all animations).

Developers should not typically need to call this method, but should an app wish to show a different experience when animators are disabled, this return value can be used as a decider of which experience to offer.

Return
Boolean boolean Whether animators are currently enabled. The default value is true.

cancel

open fun cancel(): Unit

clone

@NonNull open fun clone(): ValueAnimator

end

open fun end(): Unit

getAnimatedFraction

open fun getAnimatedFraction(): Float

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

Return
Float Elapsed/interpolated fraction of the animation.

getAnimatedValue

@NonNull open fun getAnimatedValue(): Any

The most recent value calculated by this ValueAnimator when there is just one property being animated. This value is only sensible while the animation is running. The main purpose for this read-only property is to retrieve the value from the ValueAnimator during a call to androidx.core.animation.Animator.AnimatorUpdateListener#onAnimationUpdate(Animator), which is called during each animation frame, immediately after the value is calculated.

Return
Any animatedValue The value most recently calculated by this ValueAnimator for the single property being animated. If there are several properties being animated (specified by several PropertyValuesHolder objects in the constructor), this function returns the animated value for the first of those objects.

getAnimatedValue

@Nullable open fun getAnimatedValue(@NonNull propertyName: String): Any?

The most recent value calculated by this ValueAnimator for propertyName. The main purpose for this read-only property is to retrieve the value from the ValueAnimator during a call to androidx.core.animation.Animator.AnimatorUpdateListener#onAnimationUpdate(Animator), which is called during each animation frame, immediately after the value is calculated.

Return
Any? animatedValue The value most recently calculated for the named property by this ValueAnimator.

getCurrentPlayTime

open fun getCurrentPlayTime(): Long

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started. An animation that is not yet started will return a value of zero, unless the animation has has its play time set via setCurrentPlayTime(long) or setCurrentFraction(float), in which case it will return the time that was set.

Return
Long The current position in time of the animation.

getDuration

open fun getDuration(): Long

Gets the length of the animation. The default duration is 300 milliseconds.

Return
Long The length of the animation, in milliseconds.

getFrameDelay

open static fun getFrameDelay(): Long

The amount of time, in milliseconds, between each frame of the animation. This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop. The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations. Note that this method should be called from the same thread that start() is called in order to check the frame delay for that animation. A runtime exception will be thrown if the calling thread does not have a Looper.

Return
Long the requested time between frames, in milliseconds

getInterpolator

@Nullable open fun getInterpolator(): Interpolator?

Returns the timing interpolator that this ValueAnimator uses.

Return
Interpolator? The timing interpolator for this ValueAnimator.

getNameForTrace

@NonNull open fun getNameForTrace(): String

Returns the name of this animator for debugging purposes.

getRepeatCount

open fun getRepeatCount(): Int

Defines how many times the animation should repeat. The default value is 0.

Return
Int the number of times the animation should repeat, or INFINITE

getRepeatMode

open fun getRepeatMode(): Int

Defines what this animation should do when it reaches the end.

Return
Int either one of REVERSE or RESTART

getStartDelay

open fun getStartDelay(): Long

The amount of time, in milliseconds, to delay starting the animation after start() is called.

Return
Long the number of milliseconds to delay running the animation

getTotalDuration

open fun getTotalDuration(): Long

getValues

@NonNull open fun getValues(): Array<PropertyValuesHolder!>

Returns the values that this ValueAnimator animates between. These values are stored in PropertyValuesHolder objects, even if the ValueAnimator was created with a simple list of value objects instead.

Return
Array