Added in API level 1

Animation


abstract class Animation : Cloneable
kotlin.Any
   ↳ android.view.animation.Animation

Abstraction for an Animation that can be applied to Views, Surfaces, or other objects. See the animation package.

Summary

Nested classes
abstract

An animation listener receives notifications from an animation.

open

Utility class to parse a string description of a size.

Constants
static Int

The specified dimension is an absolute number of pixels.

static Int

Repeat the animation indefinitely.

static Int

The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.

static Int

The specified dimension holds a float and should be multiplied by the height or width of the object being animated.

static Int

When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation restarts from the beginning.

static Int

When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation plays backward (and then forward again).

static Int

Can be used as the start time to indicate the start time should be the current time when getTransformation(long,android.view.animation.Transformation) is invoked for the first animation frame.

static Int

Requests that the content being animated be forced under all other content for the duration of the animation.

static Int

Requests that the content being animated be kept in its current Z order.

static Int

Requests that the content being animated be forced on top of all other content for the duration of the animation.

Public constructors

Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false

Animation(context: Context!, attrs: AttributeSet!)

Creates a new animation whose parameters come from the specified context and attributes set.

Public methods
open Unit

Cancel the animation.

open Long

Compute a hint at how long the entire animation may last, in milliseconds.

open Int

Returns the background color to show behind the animating windows.

open Int

Returns the background color behind the animation.

open Boolean

Return value of setDetachWallpaper(boolean).

open Long

How long this animation should last

open Boolean

If fillAfter is true, this animation will apply its transformation after the end time of the animation.

open Boolean

If fillBefore is true, this animation will apply its transformation before the start time of the animation.

open Interpolator!

Gets the acceleration curve type for this animation.

open Int

Defines how many times the animation should repeat.

open Int

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

open Boolean

If showBackdrop is true and this animation is applied on a window, then the windows in the animation will animate with the background associated with this window behind them.

open Long

When this animation should start, relative to StartTime

open Long

When this animation should start.

open Boolean
getTransformation(currentTime: Long, outTransformation: Transformation!)

Gets the transformation to apply at a specified point in time.

open Boolean
getTransformation(currentTime: Long, outTransformation: Transformation!, scale: Float)

Gets the transformation to apply at a specified point in time.

open Int

Returns the Z ordering mode to use while running the animation as previously set by setZAdjustment.

open Boolean

Indicates whether this animation has ended or not.

open Boolean

Indicates whether this animation has started or not.

open Unit
initialize(width: Int, height: Int, parentWidth: Int, parentHeight: Int)

Initialize this animation with the dimensions of the object being animated as well as the objects parents.

open Boolean

If fillEnabled is true, this animation will apply the value of fillBefore.

open Boolean

Whether or not the animation has been initialized.

open Unit

Reset the initialization state of this animation.

open Unit
restrictDuration(durationMillis: Long)

Ensure that the duration that this animation will run is not longer than durationMillis.

open Unit

How much to scale the duration by.

open Unit

Binds an animation listener to this animation.

open Unit
setBackdropColor(backdropColor: Int)

Set the color to use for the backdrop shown behind the animating windows.

open Unit

Set background behind animation.

open Unit
setDetachWallpaper(detachWallpaper: Boolean)

If detachWallpaper is true, and this is a window animation of a window that has a wallpaper background, then the window will be detached from the wallpaper while it runs.

open Unit
setDuration(durationMillis: Long)

How long this animation should last.

open Unit
setFillAfter(fillAfter: Boolean)

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

open Unit
setFillBefore(fillBefore: Boolean)

If fillBefore is true, this animation will apply its transformation before the start time of the animation.

open Unit
setFillEnabled(fillEnabled: Boolean)

If fillEnabled is true, the animation will apply the value of fillBefore.

open Unit
setInterpolator(context: Context!, resID: Int)

Sets the acceleration curve for this animation.

open Unit

Sets the acceleration curve for this animation.

open Unit
setRepeatCount(repeatCount: Int)

Sets how many times the animation should be repeated.

open Unit
setRepeatMode(repeatMode: Int)

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

open Unit
setShowBackdrop(showBackdrop: Boolean)

If showBackdrop is true and this animation is applied on a window, then the windows in the animation will animate with the background associated with this window behind them.

open Unit
setStartOffset(startOffset: Long)

When this animation should start relative to the start time.

open Unit
setStartTime(startTimeMillis: Long)

When this animation should start.

open Unit
setZAdjustment(zAdjustment: Int)

Set the Z ordering mode to use while running the animation.

open Unit

Convenience method to start the animation the first time getTransformation(long,android.view.animation.Transformation) is invoked.

open Unit

Convenience method to start the animation at the current time in milliseconds.

open Boolean

Indicates whether or not this animation will affect the bounds of the animated view.

open Boolean

Indicates whether or not this animation will affect the transformation matrix.

Protected methods
open Unit
applyTransformation(interpolatedTime: Float, t: Transformation!)

Helper for getTransformation.

open Animation

open Unit

Gurantees that this animation has an interpolator.

open Unit

open Float

The scale factor is set by the call to getTransformation.

open Float
resolveSize(type: Int, value: Float, size: Int, parentSize: Int)

Convert the information in the description of a size to an actual dimension

Constants

ABSOLUTE

Added in API level 1
static val ABSOLUTE: Int

The specified dimension is an absolute number of pixels.

Value: 0

INFINITE

Added in API level 1
static val INFINITE: Int

Repeat the animation indefinitely.

Value: -1

RELATIVE_TO_PARENT

Added in API level 1
static val RELATIVE_TO_PARENT: Int

The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.

Value: 2

RELATIVE_TO_SELF

Added in API level 1
static val RELATIVE_TO_SELF: Int

The specified dimension holds a float and should be multiplied by the height or width of the object being animated.

Value: 1

RESTART

Added in API level 1
static val RESTART: Int

When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation restarts from the beginning.

Value: 1

REVERSE

Added in API level 1
static val REVERSE: Int

When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation plays backward (and then forward again).

Value: 2

START_ON_FIRST_FRAME

Added in API level 1
static val START_ON_FIRST_FRAME: Int

Can be used as the start time to indicate the start time should be the current time when getTransformation(long,android.view.animation.Transformation) is invoked for the first animation frame. This can is useful for short animations.

Value: -1

ZORDER_BOTTOM

Added in API level 1
static val ZORDER_BOTTOM: Int

Requests that the content being animated be forced under all other content for the duration of the animation.

Value: -1

ZORDER_NORMAL

Added in API level 1
static val ZORDER_NORMAL: Int

Requests that the content being animated be kept in its current Z order.

Value: 0

ZORDER_TOP

Added in API level 1
static val ZORDER_TOP: Int

Requests that the content being animated be forced on top of all other content for the duration of the animation.

Value: 1

Public constructors

Animation

Added in API level 1
Animation()

Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false

Animation

Added in API level 1
Animation(
    context: Context!,
    attrs: AttributeSet!)

Creates a new animation whose parameters come from the specified context and attributes set.

Parameters
context Context!: the application environment
attrs AttributeSet!: the set of attributes holding the animation parameters

Public methods

cancel

Added in API level 8
open fun cancel(): Unit

Cancel the animation. Cancelling an animation invokes the animation listener, if set, to notify the end of the animation. If you cancel an animation manually, you must call reset() before starting the animation again.

computeDurationHint

Added in API level 3
open fun computeDurationHint(): Long

Compute a hint at how long the entire animation may last, in milliseconds. Animations can be written to cause themselves to run for a different duration than what is computed here, but generally this should be accurate.

getBackdropColor

Added in API level 33
open fun getBackdropColor(): Int

Returns the background color to show behind the animating windows. Will only show the background if showBackdrop was set to true. See setShowBackdrop(boolean).

Return
Int The backdrop color. If 0, the backdrop color will not apply.

getBackgroundColor

Added in API level 12
Deprecated in API level 30
open fun getBackgroundColor(): Int

Deprecated: None of window animations are running with background color.

Returns the background color behind the animation.

getDetachWallpaper

Added in API level 5
Deprecated in API level 29
open fun getDetachWallpaper(): Boolean

Deprecated: All window animations are running with detached wallpaper.

Return value of setDetachWallpaper(boolean).

getDuration

Added in API level 1
open fun getDuration(): Long

How long this animation should last

Return
Long the duration in milliseconds of the animation

getFillAfter

Added in API level 1
open fun getFillAfter(): Boolean

If fillAfter is true, this animation will apply its transformation after the end time of the animation.

Return
Boolean true if the animation applies its transformation after it ends

getFillBefore

Added in API level 1
open fun getFillBefore(): Boolean

If fillBefore is true, this animation will apply its transformation before the start time of the animation. If fillBefore is false and fillEnabled is true, the transformation will not be applied until the start time of the animation.

Return
Boolean true if the animation applies its transformation before it starts

getInterpolator

Added in API level 1
open fun getInterpolator(): Interpolator!

Gets the acceleration curve type for this animation.

Return
Interpolator! the Interpolator associated to this animation

getRepeatCount

Added in API level 1
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

Added in API level 1
open fun getRepeatMode(): Int

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

Return
Int either one of REVERSE or RESTART

getShowBackdrop

Added in API level 33
open fun getShowBackdrop(): Boolean

If showBackdrop is true and this animation is applied on a window, then the windows in the animation will animate with the background associated with this window behind them. If no backdrop color is explicitly set, the backdrop's color comes from the android.R.styleable#Theme_colorBackground that is applied to this window through its theme. If multiple animating windows have showBackdrop set to true during an animation, the top most window with showBackdrop set to true and a valid background color takes precedence.

Return
Boolean if a backdrop should be shown behind the animating windows.

getStartOffset

Added in API level 1
open fun getStartOffset(): Long

When this animation should start, relative to StartTime

Return
Long the start offset in milliseconds

getStartTime

Added in API level 1
open fun getStartTime(): Long

When this animation should start. If the animation has not startet yet, this method might return START_ON_FIRST_FRAME.

Return
Long the time in milliseconds when the animation should start or START_ON_FIRST_FRAME

getTransformation

Added in API level 1
open fun getTransformation(
    currentTime: Long,
    outTransformation: Transformation!
): Boolean

Gets the transformation to apply at a specified point in time. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.

Parameters
currentTime Long: Where we are in the animation. This is wall clock time.
outTransformation Transformation!: A transformation object that is provided by the caller and will be filled in by the animation.
Return
Boolean True if the animation is still running

getTransformation

Added in API level 11
open fun getTransformation(
    currentTime: Long,
    outTransformation: Transformation!,
    scale: Float
): Boolean

Gets the transformation to apply at a specified point in time. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.

Parameters
currentTime Long: Where we are in the animation. This is wall clock time.
outTransformation Transformation!: A transformation object that is provided by the caller and will be filled in by the animation.
scale Float: Scaling factor to apply to any inputs to the transform operation, such pivot points being rotated or scaled around.
Return
Boolean True if the animation is still running

getZAdjustment

Added in API level 1
open fun getZAdjustment(): Int

Returns the Z ordering mode to use while running the animation as previously set by setZAdjustment.

Return
Int Returns one of ZORDER_NORMAL, ZORDER_TOP, or ZORDER_BOTTOM.

hasEnded

Added in API level 1
open fun hasEnded(): Boolean

Indicates whether this animation has ended or not.

Return
Boolean true if the animation has ended, false otherwise

hasStarted

Added in API level 1
open fun hasStarted(): Boolean

Indicates whether this animation has started or not.

Return
Boolean true if the animation has started, false otherwise

initialize

Added in API level 1
open fun initialize(
    width: Int,
    height: Int,
    parentWidth: Int,
    parentHeight: Int
): Unit

Initialize this animation with the dimensions of the object being animated as well as the objects parents. (This is to support animation sizes being specified relative to these dimensions.)

Objects that interpret Animations should call this method when the sizes of the object being animated and its parent are known, and before calling #getTransformation.

Parameters
width Int: Width of the object being animated
height Int: Height of the object being animated
parentWidth Int: Width of the animated object's parent
parentHeight Int: Height of the animated object's parent

isFillEnabled

Added in API level 3
open fun isFillEnabled(): Boolean

If fillEnabled is true, this animation will apply the value of fillBefore.

Return
Boolean true if the animation will take fillBefore into account

isInitialized

Added in API level 1
open fun isInitialized(): Boolean

Whether or not the animation has been initialized.

Return
Boolean Has this animation been initialized.

reset

Added in API level 1
open fun reset(): Unit

Reset the initialization state of this animation.

restrictDuration

Added in API level 1
open fun restrictDuration(durationMillis: Long): Unit

Ensure that the duration that this animation will run is not longer than durationMillis. In addition to adjusting the duration itself, this ensures that the repeat count also will not make it run longer than the given time.

Parameters
durationMillis Long: The maximum duration the animation is allowed to run.

scaleCurrentDuration

Added in API level 1
open fun scaleCurrentDuration(scale: Float): Unit

How much to scale the duration by.

Parameters
scale Float: The amount to scale the duration.

setAnimationListener

Added in API level 1
open fun setAnimationListener(listener: Animation.AnimationListener!): Unit

Binds an animation listener to this animation. The animation listener is notified of animation events such as the end of the animation or the repetition of the animation.

Parameters
listener Animation.AnimationListener!: the animation listener to be notified

setBackdropColor

Added in API level 33
open fun setBackdropColor(backdropColor: Int): Unit

Set the color to use for the backdrop shown behind the animating windows. Will only show the backdrop if showBackdrop was set to true. See setShowBackdrop(boolean).

Parameters
backdropColor Int: The backdrop color. If 0, the backdrop color will not apply.

setBackgroundColor

Added in API level 12
Deprecated in API level 30
open fun setBackgroundColor(bg: Int): Unit

Deprecated: None of window animations are running with background color.

Set background behind animation.

Parameters
bg Int: The background color. If 0, no background. Currently must be black, with any desired alpha level.

setDetachWallpaper

Added in API level 5
Deprecated in API level 29
open fun setDetachWallpaper(detachWallpaper: Boolean): Unit

Deprecated: All window animations are running with detached wallpaper.

If detachWallpaper is true, and this is a window animation of a window that has a wallpaper background, then the window will be detached from the wallpaper while it runs. That is, the animation will only be applied to the window, and the wallpaper behind it will remain static.

Parameters
detachWallpaper Boolean: true if the wallpaper should be detached from the animation

setDuration

Added in API level 1
open fun setDuration(durationMillis: Long): Unit

How long this animation should last. The duration cannot be negative.

Parameters
durationMillis Long: Duration in milliseconds
Exceptions
java.lang.IllegalArgumentException if the duration is < 0

setFillAfter

Added in API level 1
open fun setFillAfter(fillAfter: Boolean): Unit

If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set. Note that this applies to individual animations and when using an to chain animations.

Parameters
fillAfter Boolean: true if the animation should apply its transformation after it ends

setFillBefore

Added in API level 1
open fun setFillBefore(fillBefore: Boolean): Unit

If fillBefore is true, this animation will apply its transformation before the start time of the animation. Defaults to true if setFillEnabled(boolean) is not set to true. Note that this applies when using an to chain animations. The transformation is not applied before the AnimationSet itself starts.

Parameters
fillBefore Boolean: true if the animation should apply its transformation before it starts

setFillEnabled

Added in API level 3
open fun setFillEnabled(fillEnabled: Boolean): Unit

If fillEnabled is true, the animation will apply the value of fillBefore. Otherwise, fillBefore is ignored and the animation transformation is always applied until the animation ends.

Parameters
fillEnabled Boolean: true if the animation should take the value of fillBefore into account

setInterpolator

Added in API level 1
open fun setInterpolator(
    context: Context!,
    resID: Int
): Unit

Sets the acceleration curve for this animation. The interpolator is loaded as a resource from the specified context.

Parameters
context Context!: The application environment
resID Int: The resource identifier of the interpolator to load

setInterpolator

Added in API level 1
open fun setInterpolator(i: Interpolator!): Unit

Sets the acceleration curve for this animation. Defaults to a linear interpolation.

Parameters
i Interpolator!: The interpolator which defines the acceleration curve

setRepeatCount

Added in API level 1
open fun setRepeatCount(repeatCount: Int): Unit

Sets how many times the animation should be repeated. If the repeat count is 0, the animation is never repeated. If the repeat count is greater than 0 or INFINITE, the repeat mode will be taken into account. The repeat count is 0 by default.

Parameters
repeatCount Int: the number of times the animation should be repeated

setRepeatMode

Added in API level 1
open fun setRepeatMode(repeatMode: Int): Unit

Defines what this animation should do when it reaches the end. This setting is applied only when the repeat count is either greater than 0 or INFINITE. Defaults to RESTART.

Parameters
repeatMode Int: RESTART or REVERSE

setShowBackdrop

Added in API level 33
open fun setShowBackdrop(showBackdrop: Boolean): Unit

If showBackdrop is true and this animation is applied on a window, then the windows in the animation will animate with the background associated with this window behind them. If no backdrop color is explicitly set, the backdrop's color comes from the android.R.styleable#Theme_colorBackground that is applied to this window through its theme. If multiple animating windows have showBackdrop set to true during an animation, the top most window with showBackdrop set to true and a valid background color takes precedence.

Parameters
showBackdrop Boolean: Whether to show a background behind the windows during the animation.

setStartOffset

Added in API level 1
open fun setStartOffset(startOffset: Long): Unit

When this animation should start relative to the start time. This is most useful when composing complex animations using an AnimationSet where some of the animations components start at different times.

Parameters
startOffset Long: When this Animation should start, in milliseconds from the start time of the root AnimationSet.

setStartTime

Added in API level 1
open fun setStartTime(startTimeMillis: Long): Unit

When this animation should start. When the start time is set to START_ON_FIRST_FRAME, the animation will start the first time getTransformation(long,android.view.animation.Transformation) is invoked. The time passed to this method should be obtained by calling AnimationUtils#currentAnimationTimeMillis() instead of System#currentTimeMillis().

Parameters
startTimeMillis Long: the start time in milliseconds

setZAdjustment

Added in API level 1
open fun setZAdjustment(zAdjustment: Int): Unit

Set the Z ordering mode to use while running the animation.

Parameters
zAdjustment Int: The desired mode, one of ZORDER_NORMAL, ZORDER_TOP, or ZORDER_BOTTOM.

start

Added in API level 1
open fun start(): Unit

Convenience method to start the animation the first time getTransformation(long,android.view.animation.Transformation) is invoked.

startNow

Added in API level 1
open fun startNow(): Unit

Convenience method to start the animation at the current time in milliseconds.

willChangeBounds

Added in API level 1
open fun willChangeBounds(): Boolean

Indicates whether or not this animation will affect the bounds of the animated view. For instance, a fade animation will not affect the bounds whereas a 200% scale animation will.

Return
Boolean true if this animation will change the view's bounds

willChangeTransformationMatrix

Added in API level 1
open fun willChangeTransformationMatrix(): Boolean

Indicates whether or not this animation will affect the transformation matrix. For instance, a fade animation will not affect the matrix whereas a scale animation will.

Return
Boolean true if this animation will change the transformation matrix

Protected methods

applyTransformation

Added in API level 1
protected open fun applyTransformation(
    interpolatedTime: Float,
    t: Transformation!
): Unit

Helper for getTransformation. Subclasses should implement this to apply their transforms given an interpolation value. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.

Parameters
interpolatedTime Float: The value of the normalized time (0.0 to 1.0) after it has been run through the interpolation function.
t Transformation!: The Transformation object to fill in with the current transforms.

clone

Added in API level 1
protected open fun clone(): Animation
Return
Animation a clone of this instance.
Exceptions
java.lang.CloneNotSupportedException if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

ensureInterpolator

Added in API level 1
protected open fun ensureInterpolator(): Unit

Gurantees that this animation has an interpolator. Will use a AccelerateDecelerateInterpolator is nothing else was specified.

finalize

Added in API level 1
protected open fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method

getScaleFactor

Added in API level 11
protected open fun getScaleFactor(): Float

The scale factor is set by the call to getTransformation. Overrides of getTransformation(long,android.view.animation.Transformation,float) will get this value directly. Overrides of applyTransformation(float,android.view.animation.Transformation) can call this method to get the value.

Return
Float float The scale factor that should be applied to pre-scaled values in an Animation such as the pivot points in ScaleAnimation and RotateAnimation.

resolveSize

Added in API level 1
protected open fun resolveSize(
    type: Int,
    value: Float,
    size: Int,
    parentSize: Int
): Float

Convert the information in the description of a size to an actual dimension

Parameters
type Int: One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
value Float: The dimension associated with the type parameter
size Int: The size of the object being animated
parentSize Int: The size of the parent of the object being animated
Return
Float The dimension to use for the animation