Animation with animationSet() in android Animation with animationSet() in android android android

Animation with animationSet() in android


If I'm not mistaking, you're shooting for a sequence of animations.

Interestingly, once you start an AnimationSet, all the animations added are ran simultaneously and not sequentially; therefore you need to setStartOffset(long offSet) for each animation that follows the first animation.

Maybe something like this will work...

as = new AnimationSet(true);as.setFillEnabled(true);as.setInterpolator(new BounceInterpolator());TranslateAnimation ta = new TranslateAnimation(-300, 100, 0, 0); ta.setDuration(2000);as.addAnimation(ta);TranslateAnimation ta2 = new TranslateAnimation(100, 0, 0, 0); ta2.setDuration(2000);ta2.setStartOffset(2000); // allowing 2000 milliseconds for ta to finishas.addAnimation(ta2);


I suggest you to use ObjectAnimator. It is very easy to implement your case. Your animation may look like this:

ObjectAnimator animator1 = ObjectAnimator.ofFloat(targetView, "translationX", -200f);animator1.setRepeatCount(0);animator1.setDuration(1000);ObjectAnimator animator2 = ObjectAnimator.ofFloat(targetView, "translationX", 100f);animator2.setRepeatCount(0);animator2.setDuration(1000);ObjectAnimator animator3 = ObjectAnimator.ofFloat(targetView, "translationX", 0f);animator3.setRepeatCount(0);animator3.setDuration(1000);//sequencial animationAnimatorSet set = new AnimatorSet();set.play(animator1).before(animator2);set.play(animator2).before(animator3);set.start();

If you are not familior with ObjectAnimator, you can check this android example tutorial:

Android View Animation Example