Added in API level 1

AnimationSet


open class AnimationSet : Animation
kotlin.Any
   ↳ android.view.animation.Animation
   ↳ android.view.animation.AnimationSet

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

When this animation should start.

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

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

open Unit
setDuration(durationMillis: Long)

Sets the duration of every child animation.

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
setRepeatMode(repeatMode: Int)

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

open Unit
setStartOffset(startOffset: Long)

When this animation should start relative to the start time.

open Unit
setStartTime(startTimeMillis: Long)

Sets the start time of this animation and all child animations

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 AnimationSet

Creates and returns a copy of this object.

Inherited functions

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

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

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

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

    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

    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

    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

    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

    clone

    Added in API level 1
    protected open fun clone(): AnimationSet

    Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

    x.clone() != x
    will be true, and that the expression:
    x.clone().getClass() == x.getClass()
    will be true, but these are not absolute requirements. While it is typically the case that:
    x.clone().equals(x)
    will be true, this is not an absolute requirement.

    By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

    By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

    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.