zmeda
zmeda

Reputation: 2909

Android animation one after another

Here is my scenario.

At first I do an animation set to my view (View.startAnimation(animationSet)) where animationSet consists of Translate + Rotate + Scale all at the same time. It works fine. on that animationSet I have fillAfter(true). After some time user click on a button and onClick I must start new ScaleAnimation on that same View. So if I do something like:

@Override
public void onClick(View v) {
    ScaleAnimation scaleAnimation = new ScaleAnimation(mOldScaleFactor, mScaleFactor, mOldScaleFactor, mScaleFactor, mPivotX, mPivotY);
    scaleAnimation.setDuration(ANIMATION_DURATION_MILIS);
    scaleAnimation.setStartOffset(ANIMATION_OFFSET_MILIS);
    scaleAnimation.setFillAfter(true);
    v.startAnimation(scaleAnimation);
}

All the previous animation (Translate + Rotete + Scale) is forgotten.

How to start new animation from where old animation ends?

Upvotes: 2

Views: 3108

Answers (1)

RightHandedMonkey
RightHandedMonkey

Reputation: 1728

You could try to implement a listener and possible capture the information from when the previous animation left off, however I'm not sure you'll be able to query the animation for its state. Another option is to make sure the animation stops into a known state. That way you can know how you need to start the next animation.

public float param1;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    //load text view to add animation
    ImageView image1 = (ImageView) findViewById(R.id.splash_imageView1);
    Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_anim);
    image1.startAnimation(fade1);
    fade1.setAnimationListener(new AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            //interrogate animation here
        }

Upvotes: 1

Related Questions