Android APIs
public class

AnimationSet

extends Animation
java.lang.Object
   ↳ android.view.animation.Animation
     ↳ android.view.animation.AnimationSet

Class Overview

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

[Expand]
Inherited XML Attributes
From class android.view.animation.Animation
[Expand]
Inherited Constants
From class android.view.animation.Animation
Public Constructors
AnimationSet(Context context, AttributeSet attrs)
Constructor used when an AnimationSet is loaded from a resource.
AnimationSet(boolean shareInterpolator)
Constructor to use when building an AnimationSet from code
Public Methods
void addAnimation(Animation a)
Add a child animation to this animation set.
long computeDurationHint()
The duration hint of an animation set is the maximum of the duration hints of all of its component animations.
List<Animation> getAnimations()
long getDuration()
The duration of an AnimationSet is defined to be the duration of the longest child animation.
long getStartTime()
When this animation should start.
boolean getTransformation(long currentTime, Transformation t)
The transformation of an animation set is the concatenation of all of its component animations.
void initialize(int width, int height, int parentWidth, int parentHeight)
Initialize this animation with the dimensions of the object being animated as well as the objects parents.
void reset()
Reset the initialization state of this animation.
void restrictDuration(long durationMillis)
Ensure that the duration that this animation will run is not longer than durationMillis.
void scaleCurrentDuration(float scale)
How much to scale the duration by.
void setDuration(long durationMillis)

Sets the duration of every child animation.

void setFillAfter(boolean fillAfter)
If fillAfter is true, the transformation that this animation performed will persist when it is finished.
void setFillBefore(boolean fillBefore)
If fillBefore is true, this animation will apply its transformation before the start time of the animation.
void setRepeatMode(int repeatMode)
Defines what this animation should do when it reaches the end.
void setStartOffset(long startOffset)
When this animation should start relative to the start time.
void setStartTime(long startTimeMillis)
Sets the start time of this animation and all child animations
boolean willChangeBounds()

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

boolean willChangeTransformationMatrix()

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

Protected Methods
AnimationSet clone()
Creates and returns a copy of this Object.
[Expand]
Inherited Methods
From class android.view.animation.Animation
From class java.lang.Object

Public Constructors

public AnimationSet (Context context, AttributeSet attrs)

Added in API level 1

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

public AnimationSet (boolean shareInterpolator)

Added in API level 1

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

public void addAnimation (Animation a)

Added in API level 1

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.

public long computeDurationHint ()

Added in API level 3

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

Returns
long

public List<Animation> getAnimations ()

Added in API level 1

Returns
List<Animation> All the child animations in this AnimationSet. Note that this may include other AnimationSets, which are not expanded.

public long getDuration ()

Added in API level 1

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

Returns
long the duration in milliseconds of the animation

See also:

public long getStartTime ()

Added in API level 1

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

Returns
long the time in milliseconds when the animation should start or START_ON_FIRST_FRAME

public boolean getTransformation (long currentTime, Transformation t)

Added in API level 1

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.
t Transformation: A transformation object that is provided by the caller and will be filled in by the animation.
Returns
boolean True if the animation is still running

public void initialize (int width, int height, int parentWidth, int parentHeight)

Added in API level 1

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(long, Transformation).

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

public void reset ()

Added in API level 1

Reset the initialization state of this animation.

public void restrictDuration (long durationMillis)

Added in API level 1

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.

public void scaleCurrentDuration (float scale)

Added in API level 1

How much to scale the duration by.

Parameters
scale float: The amount to scale the duration.

public void setDuration (long durationMillis)

Added in API level 1

Sets the duration of every child animation.

Parameters
durationMillis long: the duration of the animation, in milliseconds, for every child in this set

public void setFillAfter (boolean fillAfter)

Added in API level 1

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

public void setFillBefore (boolean fillBefore)

Added in API level 1

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

public void setRepeatMode (int repeatMode)

Added in API level 1

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

public void setStartOffset (long startOffset)

Added in API level 1

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.

public void setStartTime (long startTimeMillis)

Added in API level 1

Sets the start time of this animation and all child animations

Parameters
startTimeMillis long: the start time in milliseconds

See also:

public boolean willChangeBounds ()

Added in API level 1

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.

Returns
boolean true if this animation will change the view's bounds

public boolean willChangeTransformationMatrix ()

Added in API level 1

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.

Returns
boolean true if this animation will change the transformation matrix

Protected Methods

protected AnimationSet clone ()

Added in API level 1

Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
AnimationSet a copy of this object.
Throws
CloneNotSupportedException