Most visited

Recently visited

Added in API level 1

LayoutAnimationController

public class LayoutAnimationController
extends Object

java.lang.Object
   ↳ android.view.animation.LayoutAnimationController
Known Direct Subclasses


A layout animation controller is used to animated a layout's, or a view group's, children. Each child uses the same animation but for every one of them, the animation starts at a different time. A layout animation controller is used by ViewGroup to compute the delay by which each child's animation start must be offset. The delay is computed by using characteristics of each child, like its index in the view group. This standard implementation computes the delay by multiplying a fixed amount of miliseconds by the index of the child in its parent view group. Subclasses are supposed to override getDelayForView(android.view.View) to implement a different way of computing the delay. For instance, a GridLayoutAnimationController will compute the delay based on the column and row indices of the child in its parent view group. Information used to compute the animation delay of each child are stored in an instance of LayoutAnimationController.AnimationParameters, itself stored in the ViewGroup.LayoutParams of the view.

Summary

Nested classes

class LayoutAnimationController.AnimationParameters

The set of parameters that has to be attached to each view contained in the view group animated by the layout animation controller. 

XML attributes

android:animation Animation to use on each child. 
android:animationOrder The order in which the animations will be started. 
android:delay Fraction of the animation duration used to delay the beginning of the animation of each child. 
android:interpolator Interpolator used to interpolate the delay between the start of each animation. 

Constants

int ORDER_NORMAL

Distributes the animation delays in the order in which view were added to their view group.

int ORDER_RANDOM

Randomly distributes the animation delays.

int ORDER_REVERSE

Distributes the animation delays in the reverse order in which view were added to their view group.

Fields

protected Animation mAnimation

The animation applied on each child of the view group on which this layout animation controller is set.

protected Interpolator mInterpolator

The interpolator used to interpolate the delays.

protected Random mRandomizer

The randomizer used when the order is set to random.

Public constructors

LayoutAnimationController(Context context, AttributeSet attrs)

Creates a new layout animation controller from external resources.

LayoutAnimationController(Animation animation)

Creates a new layout animation controller with a delay of 50% and the specified animation.

LayoutAnimationController(Animation animation, float delay)

Creates a new layout animation controller with the specified delay and the specified animation.

Public methods

Animation getAnimation()

Returns the animation applied to each child of the view group on which this controller is set.

final Animation getAnimationForView(View view)

Returns the animation to be applied to the specified view.

float getDelay()

Returns the delay by which the children's animation are offset.

Interpolator getInterpolator()

Returns the interpolator used to interpolate the delays between the children.

int getOrder()

Returns the order used to compute the delay of each child's animation.

boolean isDone()

Indicates whether the layout animation is over or not.

void setAnimation(Animation animation)

Sets the animation to be run on each child of the view group on which this layout animation controller is .

void setAnimation(Context context, int resourceID)

Sets the animation to be run on each child of the view group on which this layout animation controller is .

void setDelay(float delay)

Sets the delay, as a fraction of the animation duration, by which the children's animations are offset.

void setInterpolator(Context context, int resourceID)

Sets the interpolator used to interpolate the delays between the children.

void setInterpolator(Interpolator interpolator)

Sets the interpolator used to interpolate the delays between the children.

void setOrder(int order)

Sets the order used to compute the delay of each child's animation.

void start()

Starts the animation.

boolean willOverlap()

Indicates whether two children's animations will overlap.

Protected methods

long getDelayForView(View view)

Returns the amount of milliseconds by which the specified view's animation must be delayed or offset.

int getTransformedIndex(LayoutAnimationController.AnimationParameters params)

Transforms the index stored in LayoutAnimationController.AnimationParameters by the order returned by getOrder().

Inherited methods

From class java.lang.Object

XML attributes

android:animation

Animation to use on each child.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol animation.

Related methods:

android:animationOrder

The order in which the animations will be started.

Must be one of the following constant values.

ConstantValueDescription
normal0 Animations are started in the natural order.
reverse1 Animations are started in the reverse order.
random2 Animations are started randomly.

This corresponds to the global attribute resource symbol animationOrder.

Related methods:

android:delay

Fraction of the animation duration used to delay the beginning of the animation of each child.

May be a floating point value, such as "1.2".

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol delay.

android:interpolator

Interpolator used to interpolate the delay between the start of each animation.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol interpolator.

Related methods:

Constants

ORDER_NORMAL

Added in API level 1
int ORDER_NORMAL

Distributes the animation delays in the order in which view were added to their view group.

Constant Value: 0 (0x00000000)

ORDER_RANDOM

Added in API level 1
int ORDER_RANDOM

Randomly distributes the animation delays.

Constant Value: 2 (0x00000002)

ORDER_REVERSE

Added in API level 1
int ORDER_REVERSE

Distributes the animation delays in the reverse order in which view were added to their view group.

Constant Value: 1 (0x00000001)

Fields

mAnimation

Added in API level 1
Animation mAnimation

The animation applied on each child of the view group on which this layout animation controller is set.

mInterpolator

Added in API level 1
Interpolator mInterpolator

The interpolator used to interpolate the delays.

mRandomizer

Added in API level 1
Random mRandomizer

The randomizer used when the order is set to random. Subclasses should use this object to avoid creating their own.

Public constructors

LayoutAnimationController

Added in API level 1
LayoutAnimationController (Context context, 
                AttributeSet attrs)

Creates a new layout animation controller from external resources.

Parameters
context Context: the Context the view group is running in, through which it can access the resources
attrs AttributeSet: the attributes of the XML tag that is inflating the layout animation controller

LayoutAnimationController

Added in API level 1
LayoutAnimationController (Animation animation)

Creates a new layout animation controller with a delay of 50% and the specified animation.

Parameters
animation Animation: the animation to use on each child of the view group

LayoutAnimationController

Added in API level 1
LayoutAnimationController (Animation animation, 
                float delay)

Creates a new layout animation controller with the specified delay and the specified animation.

Parameters
animation Animation: the animation to use on each child of the view group
delay float: the delay by which each child's animation must be offset

Public methods

getAnimation

Added in API level 1
Animation getAnimation ()

Returns the animation applied to each child of the view group on which this controller is set.

Returns
Animation an Animation instance

See also:

getAnimationForView

Added in API level 1
Animation getAnimationForView (View view)

Returns the animation to be applied to the specified view. The returned animation is delayed by an offset computed according to the information provided by LayoutAnimationController.AnimationParameters. This method is called by view groups to obtain the animation to set on a specific child.

Parameters
view View: the view to animate
Returns
Animation an animation delayed by the number of milliseconds returned by getDelayForView(android.view.View)

See also:

getDelay

Added in API level 1
float getDelay ()

Returns the delay by which the children's animation are offset. The delay is expressed as a fraction of the animation duration.

Returns
float a fraction of the animation duration

See also:

getInterpolator

Added in API level 1
Interpolator getInterpolator ()

Returns the interpolator used to interpolate the delays between the children.

Returns
Interpolator an Interpolator

getOrder

Added in API level 1
int getOrder ()

Returns the order used to compute the delay of each child's animation.

Related XML Attributes:

Returns
int one of ORDER_NORMAL, ORDER_REVERSE or {@link #ORDER_RANDOM)

isDone

Added in API level 1
boolean isDone ()

Indicates whether the layout animation is over or not. A layout animation is considered done when the animation with the longest delay is done.

Returns
boolean true if all of the children's animations are over, false otherwise

setAnimation

Added in API level 1
void setAnimation (Animation animation)

Sets the animation to be run on each child of the view group on which this layout animation controller is .

Related XML Attributes:

Parameters
animation Animation: the animation to run on each child of the view group

See also:

setAnimation

Added in API level 1
void setAnimation (Context context, 
                int resourceID)

Sets the animation to be run on each child of the view group on which this layout animation controller is .

Related XML Attributes:

Parameters
context Context: the context from which the animation must be inflated
resourceID int: the resource identifier of the animation

See also:

setDelay

Added in API level 1
void setDelay (float delay)

Sets the delay, as a fraction of the animation duration, by which the children's animations are offset. The general formula is:

 child animation delay = child index * delay * animation duration
 

Parameters
delay float: a fraction of the animation duration

See also:

setInterpolator

Added in API level 1
void setInterpolator (Context context, 
                int resourceID)

Sets the interpolator used to interpolate the delays between the children.

Related XML Attributes:

Parameters
context Context: the context from which the interpolator must be inflated
resourceID int: the resource identifier of the interpolator

See also:

setInterpolator

Added in API level 1
void setInterpolator (Interpolator interpolator)

Sets the interpolator used to interpolate the delays between the children.

Related XML Attributes:

Parameters
interpolator Interpolator: the interpolator

See also:

setOrder

Added in API level 1
void setOrder (int order)

Sets the order used to compute the delay of each child's animation.

Related XML Attributes:

Parameters
order int: one of ORDER_NORMAL, ORDER_REVERSE or ORDER_RANDOM

start

Added in API level 1
void start ()

Starts the animation.

willOverlap

Added in API level 1
boolean willOverlap ()

Indicates whether two children's animations will overlap. Animations overlap when the delay is lower than 100% (or 1.0).

Returns
boolean true if animations will overlap, false otherwise

Protected methods

getDelayForView

Added in API level 1
long getDelayForView (View view)

Returns the amount of milliseconds by which the specified view's animation must be delayed or offset. Subclasses should override this method to return a suitable value. This implementation returns child animation delay milliseconds where:

 child animation delay = child index * delay
 
The index is retrieved from the LayoutAnimationController.AnimationParameters found in the view's ViewGroup.LayoutParams.

Parameters
view View: the view for which to obtain the animation's delay
Returns
long a delay in milliseconds

See also:

getTransformedIndex

Added in API level 1
int getTransformedIndex (LayoutAnimationController.AnimationParameters params)

Transforms the index stored in LayoutAnimationController.AnimationParameters by the order returned by getOrder(). Subclasses should override this method to provide additional support for other types of ordering. This method should be invoked by getDelayForView(android.view.View) prior to any computation.

Parameters
params LayoutAnimationController.AnimationParameters: the animation parameters containing the index
Returns
int a transformed index

Hooray!