Added in API level 1

AnimationSet


open class AnimationSet : Animation

Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore), the values of AnimationSet override the child values.

The way that AnimationSet inherits behavior from Animation is important to understand. Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:

  • duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object, will be pushed down to all child animations.
  • repeatCount, fillEnabled: These properties are ignored for AnimationSet.
  • startOffset, shareInterpolator: These properties apply to the AnimationSet itself.
Starting with android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, the behavior of these properties is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored for AnimationSet). That is, calling setDuration(500) on an AnimationSet has the same effect as declaring android:duration="500" in an XML resource for an AnimationSet object.

Summary

Inherited constants
Int ABSOLUTE

The specified dimension is an absolute number of pixels.

Int INFINITE

Repeat the animation indefinitely.

Int RELATIVE_TO_PARENT

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

Int RELATIVE_TO_SELF

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

Int RESTART

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

Int REVERSE

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).

Int START_ON_FIRST_FRAME

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.

Int ZORDER_BOTTOM

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

Int ZORDER_NORMAL

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

Int ZORDER_TOP

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

Public constructors
AnimationSet(context: Context!, attrs: AttributeSet!)

Constructor used when an AnimationSet is loaded from a resource.

AnimationSet(shareInterpolator: Boolean)

Constructor to use when building an AnimationSet from code

Public methods
open Unit

Add a child animation to this animation set.

open Long

The duration hint of an animation set is the maximum of the duration hints of all of its component animations.

open MutableList<Animation!>!

open Long

The duration of an AnimationSet is defined to be the duration of the longest child animation.

open Long

open Boolean

The transformation of an animation set is the concatenation of all of its component animations.

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

open Unit

open Unit
restrictDuration(durationMillis: Long)

open Unit

open Unit
setDuration(durationMillis: Long)

Sets the duration of every child animation.

open Unit
setFillAfter(fillAfter: Boolean)

open Unit
setFillBefore(fillBefore: Boolean)

open Unit
setRepeatMode(repeatMode: Int)

open Unit
setStartOffset(startOffset: Long)

open Unit
setStartTime(startTimeMillis: Long)

Sets the start time of this animation and all child animations

open Boolean

open Boolean

Protected methods
open AnimationSet

Inherited functions
Unit applyTransformation(interpolatedTime: Float, t: Transformation!)

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.

Unit cancel()

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.

Unit ensureInterpolator()

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

Unit finalize()

Int getBackdropColor()

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

Int getBackgroundColor()

Returns the background color behind the animation.

Boolean getDetachWallpaper()

Return value of setDetachWallpaper(boolean).

Boolean getFillAfter()

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

Boolean getFillBefore()

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.

Interpolator! getInterpolator()

Gets the acceleration curve type for this animation.

Int getRepeatCount()

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

Int getRepeatMode()

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

Float getScaleFactor()

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.

Boolean getShowBackdrop()

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.

Long getStartOffset()

When this animation should start, relative to StartTime

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

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.

Int getZAdjustment()

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

Boolean hasEnded()

Indicates whether this animation has ended or not.

Boolean hasStarted()

Indicates whether this animation has started or not.

Boolean isFillEnabled()

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

Boolean isInitialized()

Whether or not the animation has been initialized.

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

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

Unit setAnimationListener(listener: Animation.AnimationListener!)

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.

Unit setBackdropColor(backdropColor: Int)

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).

Unit setBackgroundColor(bg: Int)

Set background behind animation.

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. That is, the animation will only be applied to the window, and the wallpaper behind it will remain static.

Unit setFillEnabled(fillEnabled: Boolean)

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.

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

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

Unit setInterpolator(i: Interpolator!)

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

Unit setRepeatCount(repeatCount: Int)

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.

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. 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.

Unit setZAdjustment(zAdjustment: Int)

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

Unit start()

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

Unit startNow()

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

Public constructors

AnimationSet

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

Constructor used when an AnimationSet is loaded from a resource.

Parameters
context Context!: Application context to use
attrs AttributeSet!: Attribute set from which to read values

AnimationSet

Added in API level 1
AnimationSet(shareInterpolator: Boolean)

Constructor to use when building an AnimationSet from code

Parameters
shareInterpolator Boolean: Pass true if all of the animations in this set should use the interpolator associated with this AnimationSet. Pass false if each animation should use its own interpolator.

Public methods

addAnimation

Added in API level 1
open fun addAnimation(a: Animation!): Unit

Add a child animation to this animation set. The transforms of the child animations are applied in the order that they were added

Parameters
a Animation!: Animation to add.

computeDurationHint

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

The duration hint of an animation set is the maximum of the duration hints of all of its component animations.

getAnimations

Added in API level 1
open fun getAnimations(): MutableList<Animation!>!
Return
MutableList<Animation!>! All the child animations in this AnimationSet. Note that this may include other AnimationSets, which are not expanded.

getDuration

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

The duration of an AnimationSet is defined to be the duration of the longest child animation.

Return
Long the duration in milliseconds of the animation

getStartTime

Added in API level 1
open fun getStartTime(): Long
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,
    t: Transformation!
): Boolean

The transformation of an animation set is the concatenation of all of its component animations.

Parameters
currentTime Long: Where we are in the animation. This is wall clock time.
outTransformation 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

See Also

    initialize

    Added in API level 1
    open fun initialize(
        width: Int,
        height: Int,
        parentWidth: Int,
        parentHeight: Int
    ): Unit
    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

    reset

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

    restrictDuration

    Added in API level 1
    open fun restrictDuration(durationMillis: Long): Unit
    Parameters
    durationMillis Long: The maximum duration the animation is allowed to run.

    scaleCurrentDuration

    Added in API level 1
    open fun scaleCurrentDuration(scale: Float): Unit
    Parameters
    scale Float: The amount to scale the duration.

    setDuration

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

    Sets the duration of every child animation.

    Parameters
    durationMillis Long: the duration of the animation, in milliseconds, for every child in this set
    Exceptions
    java.lang.IllegalArgumentException if the duration is < 0

    setFillAfter

    Added in API level 1
    open fun setFillAfter(fillAfter: Boolean): Unit
    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
    Parameters
    fillBefore Boolean: true if the animation should apply its transformation before it starts

    setRepeatMode

    Added in API level 1
    open fun setRepeatMode(repeatMode: Int): Unit
    Parameters
    repeatMode Int: RESTART or REVERSE

    setStartOffset

    Added in API level 1
    open fun setStartOffset(startOffset: Long): Unit
    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

    Sets the start time of this animation and all child animations

    Parameters
    startTimeMillis Long: the start time in milliseconds

    willChangeBounds

    Added in API level 1
    open fun willChangeBounds(): Boolean
    Return
    Boolean true if this animation will change the view's bounds

    willChangeTransformationMatrix

    Added in API level 1
    open fun willChangeTransformationMatrix(): Boolean
    Return
    Boolean true if this animation will change the transformation matrix

    Protected methods

    clone

    Added in API level 1
    protected open fun clone(): AnimationSet
    Return
    AnimationSet 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.