0

I'm trying to play animations one after another on pre-honeycomb devices.

I've tried to play animations one after another using the AnimationSet and the startOffset value of each animation without luck.

I've also tried to create a new class that manages the animations to start one after another, but it also doesn't work.

Here's the code:

public class AnimationChain {

    private final List<Animation> mAnimations = new ArrayList<Animation>();
    private AnimationListener mAnimationListener;
    private final View mViewToAnimate;

    public AnimationChain(final View viewToAnimate) {
        this.mViewToAnimate = viewToAnimate;
    }

    public void addAnimation(final Animation animation) {
        mAnimations.add(animation);
    }

    public void setAnimationListener(final AnimationListener animationListener) {
        this.mAnimationListener = animationListener;
    }

    public List<Animation> getAnimations() {
        return this.mAnimations;
    }

    public Animation getLastAnimation() {
        final int size = mAnimations.size();
        if (size == 0)
            return null;
        return mAnimations.get(size - 1);
    }

    public void startAnimations() {
        if (mAnimations.size() == 0)
            return;
        for (int i = 0; i < mAnimations.size(); ++i) {
            final Animation currentAnimation = mAnimations.get(i);
            final Animation nextAnimation;
            if (i != mAnimations.size() - 1)
                nextAnimation = mAnimations.get(i + 1);
            else
                nextAnimation = null;
            currentAnimation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(final Animation animation) {
                    if (mAnimationListener != null)
                        mAnimationListener.onAnimationStart(animation);
                }

                @Override
                public void onAnimationRepeat(final Animation animation) {
                    if (mAnimationListener != null)
                        mAnimationListener.onAnimationRepeat(animation);
                }

                @Override
                public void onAnimationEnd(final Animation animation) {
                    if (mAnimationListener != null)
                        mAnimationListener.onAnimationEnd(animation);
                    if (nextAnimation != null)
                        mViewToAnimate.startAnimation(nextAnimation);
                }
            });
        }
        final Animation firstAnimation = mAnimations.get(0);
        mViewToAnimate.startAnimation(firstAnimation);
    }
}

It seems that it does call the next animation to start, but it doesn't do anything that I can see. Using a single animation works fine for any animation though.

Can anyone please help me? What have I done wrong?

Also, if I try to work on honeycomb version and above, will this problem still exist ? How will I handle it there? Maybe using the 9-old-android library can help?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

0

What Animations are you using? I tried it with a TranslateAnimation and RotateAnimation, it is working. Also where are you calling the startAnimations from?

Aswin Rajendiran
  • 3,399
  • 1
  • 21
  • 18
  • i tried a translate animation that "moves" the view to the side and then scale animation to show that it's being squeezed and bounce back. maybe i didn't do a good job at it? – android developer May 06 '13 at 06:08
  • sadly because it didn't work i've deleted the whole thing. i hope i will have a chance of trying it out again. – android developer May 06 '13 at 07:21