LayoutAnimationController
open class LayoutAnimationController
kotlin.Any | |
↳ | android.view.animation.LayoutAnimationController |
A layout animation controller is used to animate the children of a layout or a view group. 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 android.view.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 android.view.animation.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 android.view.animation.LayoutAnimationController.AnimationParameters
, itself stored in the android.view.ViewGroup.LayoutParams
of the view.
Summary
Nested classes | |
---|---|
open |
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 | |
---|---|
static Int |
Distributes the animation delays in the order in which view were added to their view group. |
static Int |
Randomly distributes the animation delays. |
static Int |
Distributes the animation delays in the reverse order in which view were added to their view group. |
Public constructors | |
---|---|
LayoutAnimationController(context: Context!, attrs: AttributeSet!) 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!, delay: Float) Creates a new layout animation controller with the specified delay and the specified animation. |
Public methods | |
---|---|
open Animation! |
Returns the animation applied to each child of the view group on which this controller is set. |
Animation! |
getAnimationForView(view: View!) Returns the animation to be applied to the specified view. |
open Float |
getDelay() Returns the delay by which the children's animation are offset. |
open Interpolator! |
Returns the interpolator used to interpolate the delays between the children. |
open Int |
getOrder() Returns the order used to compute the delay of each child's animation. |
open Boolean |
isDone() Indicates whether the layout animation is over or not. |
open Unit |
setAnimation(context: Context!, resourceID: Int) Sets the animation to be run on each child of the view group on which this layout animation controller is . |
open Unit |
setAnimation(animation: Animation!) Sets the animation to be run on each child of the view group on which this layout animation controller is . |
open Unit |
Sets the delay, as a fraction of the animation duration, by which the children's animations are offset. |
open Unit |
setInterpolator(context: Context!, resourceID: Int) Sets the interpolator used to interpolate the delays between the children. |
open Unit |
setInterpolator(interpolator: Interpolator!) Sets the interpolator used to interpolate the delays between the children. |
open Unit |
Sets the order used to compute the delay of each child's animation. |
open Unit |
start() Starts the animation. |
open Boolean |
Indicates whether two children's animations will overlap. |
Protected methods | |
---|---|
open Long |
getDelayForView(view: View!) Returns the amount of milliseconds by which the specified view's animation must be delayed or offset. |
open Int |
Transforms the index stored in |
Properties | |
---|---|
Animation! |
The animation applied on each child of the view group on which this layout animation controller is set. |
Interpolator! |
The interpolator used to interpolate the delays. |
Random! |
The randomizer used when the order is set to random. |
XML attributes
android:animation
android:animation
Animation to use on each child.
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
android:animationOrder
android:animationOrder
The order in which the animations will be started.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
normal | 0 | Animations are started in the natural order. |
random | 2 | Animations are started randomly. |
reverse | 1 | Animations are started in the reverse order. |
android:delay
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.
android:interpolator
android:interpolator
Interpolator used to interpolate the delay between the start of each animation.
May be a reference to another resource, in the form "@[+][package:]type/name
" or a theme attribute in the form "?[package:]type/name
".
Constants
ORDER_NORMAL
static val ORDER_NORMAL: Int
Distributes the animation delays in the order in which view were added to their view group.
Value: 0
ORDER_RANDOM
static val ORDER_RANDOM: Int
Randomly distributes the animation delays.
Value: 2
ORDER_REVERSE
static val ORDER_REVERSE: Int
Distributes the animation delays in the reverse order in which view were added to their view group.
Value: 1
Public constructors
LayoutAnimationController
LayoutAnimationController(
context: Context!,
attrs: AttributeSet!)
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
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
LayoutAnimationController(
animation: Animation!,
delay: Float)
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
open fun getAnimation(): Animation!
Returns the animation applied to each child of the view group on which this controller is set.
Return | |
---|---|
Animation! |
an android.view.animation.Animation instance |
getAnimationForView
fun getAnimationForView(view: View!): Animation!
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 android.view.animation.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 |
Return | |
---|---|
Animation! |
an animation delayed by the number of milliseconds returned by getDelayForView(android.view.View) |
getDelay
open fun getDelay(): Float
Returns the delay by which the children's animation are offset. The delay is expressed as a fraction of the animation duration.
Return | |
---|---|
Float |
a fraction of the animation duration |
See Also
getInterpolator
open fun getInterpolator(): Interpolator!
Returns the interpolator used to interpolate the delays between the children.
Return | |
---|---|
Interpolator! |
an android.view.animation.Interpolator |
getOrder
open fun getOrder(): Int
Returns the order used to compute the delay of each child's animation.
Return | |
---|---|
Int |
one of ORDER_NORMAL , ORDER_REVERSE or ORDER_RANDOM |
isDone
open fun isDone(): Boolean
Indicates whether the layout animation is over or not. A layout animation is considered done when the animation with the longest delay is done.
Return | |
---|---|
Boolean |
true if all of the children's animations are over, false otherwise |
setAnimation
open fun setAnimation(
context: Context!,
resourceID: Int
): Unit
Sets the animation to be run on each child of the view group on which this layout animation controller is .
Parameters | |
---|---|
context |
Context!: the context from which the animation must be inflated |
resourceID |
Int: the resource identifier of the animation |
See Also
setAnimation
open fun setAnimation(animation: Animation!): Unit
Sets the animation to be run on each child of the view group on which this layout animation controller is .
Parameters | |
---|---|
animation |
Animation!: the animation to run on each child of the view group |
setDelay
open fun setDelay(delay: Float): Unit
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
open fun setInterpolator(
context: Context!,
resourceID: Int
): Unit
Sets the interpolator used to interpolate the delays between the children.
Parameters | |
---|---|
context |
Context!: the context from which the interpolator must be inflated |
resourceID |
Int: the resource identifier of the interpolator |
setInterpolator
open fun setInterpolator(interpolator: Interpolator!): Unit
Sets the interpolator used to interpolate the delays between the children.
Parameters | |
---|---|
interpolator |
Interpolator!: the interpolator |
setOrder
open fun setOrder(order: Int): Unit
Sets the order used to compute the delay of each child's animation.
Parameters | |
---|---|
order |
Int: one of ORDER_NORMAL , ORDER_REVERSE or ORDER_RANDOM |
willOverlap
open fun willOverlap(): Boolean
Indicates whether two children's animations will overlap. Animations overlap when the delay is lower than 100% (or 1.0).
Return | |
---|---|
Boolean |
true if animations will overlap, false otherwise |
Protected methods
getDelayForView
protected open fun getDelayForView(view: View!): Long
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 * delayThe index is retrieved from the
android.view.animation.LayoutAnimationController.AnimationParameters
found in the view's android.view.ViewGroup.LayoutParams
.
Parameters | |
---|---|
view |
View!: the view for which to obtain the animation's delay |
Return | |
---|---|
Long |
a delay in milliseconds |
getTransformedIndex
protected open fun getTransformedIndex(params: LayoutAnimationController.AnimationParameters!): Int
Transforms the index stored in android.view.animation.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 |
Return | |
---|---|
Int |
a transformed index |
Properties
mAnimation
protected var mAnimation: Animation!
The animation applied on each child of the view group on which this layout animation controller is set.
mInterpolator
protected var mInterpolator: Interpolator!
The interpolator used to interpolate the delays.
mRandomizer
protected var mRandomizer: Random!
The randomizer used when the order is set to random. Subclasses should use this object to avoid creating their own.