Constructors Summary |
---|
public LayoutAnimationController(android.content.Context context, android.util.AttributeSet attrs)Creates a new layout animation controller from external resources.
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.LayoutAnimation);
Animation.Description d = Animation.Description.parseValue(
a.peekValue(com.android.internal.R.styleable.LayoutAnimation_delay));
mDelay = d.value;
mOrder = a.getInt(com.android.internal.R.styleable.LayoutAnimation_animationOrder, ORDER_NORMAL);
int resource = a.getResourceId(com.android.internal.R.styleable.LayoutAnimation_animation, 0);
if (resource > 0) {
setAnimation(context, resource);
}
resource = a.getResourceId(com.android.internal.R.styleable.LayoutAnimation_interpolator, 0);
if (resource > 0) {
setInterpolator(context, resource);
}
a.recycle();
|
public LayoutAnimationController(Animation animation)Creates a new layout animation controller with a delay of 50%
and the specified animation.
this(animation, 0.5f);
|
public LayoutAnimationController(Animation animation, float delay)Creates a new layout animation controller with the specified delay
and the specified animation.
mDelay = delay;
setAnimation(animation);
|
Methods Summary |
---|
public Animation | getAnimation()Returns the animation applied to each child of the view group on which
this controller is set.
return mAnimation;
|
public final Animation | getAnimationForView(android.view.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
{@link android.view.animation.LayoutAnimationController.AnimationParameters}.
This method is called by view groups to obtain the animation to set on
a specific child.
final long delay = getDelayForView(view) + mAnimation.getStartOffset();
mMaxDelay = Math.max(mMaxDelay, delay);
try {
final Animation animation = mAnimation.clone();
animation.setStartOffset(delay);
return animation;
} catch (CloneNotSupportedException e) {
return null;
}
|
public float | getDelay()Returns the delay by which the children's animation are offset. The
delay is expressed as a fraction of the animation duration.
return mDelay;
|
protected long | getDelayForView(android.view.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
{@link android.view.animation.LayoutAnimationController.AnimationParameters}
found in the view's {@link android.view.ViewGroup.LayoutParams}.
ViewGroup.LayoutParams lp = view.getLayoutParams();
AnimationParameters params = lp.layoutAnimationParameters;
if (params == null) {
return 0;
}
final float delay = mDelay * mAnimation.getDuration();
final long viewDelay = (long) (getTransformedIndex(params) * delay);
final float totalDelay = delay * params.count;
if (mInterpolator == null) {
mInterpolator = new LinearInterpolator();
}
float normalizedDelay = viewDelay / totalDelay;
normalizedDelay = mInterpolator.getInterpolation(normalizedDelay);
return (long) (normalizedDelay * totalDelay);
|
public Interpolator | getInterpolator()Returns the interpolator used to interpolate the delays between the
children.
return mInterpolator;
|
public int | getOrder()Returns the order used to compute the delay of each child's animation.
return mOrder;
|
protected int | getTransformedIndex(android.view.animation.LayoutAnimationController$AnimationParameters params)Transforms the index stored in
{@link android.view.animation.LayoutAnimationController.AnimationParameters}
by the order returned by {@link #getOrder()}. Subclasses should override
this method to provide additional support for other types of ordering.
This method should be invoked by
{@link #getDelayForView(android.view.View)} prior to any computation.
switch (getOrder()) {
case ORDER_REVERSE:
return params.count - 1 - params.index;
case ORDER_RANDOM:
if (mRandomizer == null) {
mRandomizer = new Random();
}
return (int) (params.count * mRandomizer.nextFloat());
case ORDER_NORMAL:
default:
return params.index;
}
|
public 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.
return AnimationUtils.currentAnimationTimeMillis() >
mAnimation.getStartTime() + mMaxDelay + mDuration;
|
public void | setAnimation(android.content.Context context, int resourceID)Sets the animation to be run on each child of the view group on which
this layout animation controller is .
setAnimation(AnimationUtils.loadAnimation(context, resourceID));
|
public void | setAnimation(Animation animation)Sets the animation to be run on each child of the view group on which
this layout animation controller is .
mAnimation = animation;
mAnimation.setFillBefore(true);
|
public 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
mDelay = delay;
|
public void | setInterpolator(Interpolator interpolator)Sets the interpolator used to interpolate the delays between the
children.
mInterpolator = interpolator;
|
public void | setInterpolator(android.content.Context context, int resourceID)Sets the interpolator used to interpolate the delays between the
children.
setInterpolator(AnimationUtils.loadInterpolator(context, resourceID));
|
public void | setOrder(int order)Sets the order used to compute the delay of each child's animation.
mOrder = order;
|
public void | start()Starts the animation.
mDuration = mAnimation.getDuration();
mMaxDelay = Long.MIN_VALUE;
mAnimation.setStartTime(-1);
|
public boolean | willOverlap()Indicates whether two children's animations will overlap. Animations
overlap when the delay is lower than 100% (or 1.0).
return mDelay < 1.0f;
|