Reputation: 58
I am moving an object around the screen using animations but the animation seem to run at the same time. For example, when i choose up and down the object stays put. With 2 ups and a down the object moves up 1. I'd like it to move up 1, then down 1 and up 1 again. Any way to do this? Here is my code:
int totalx = 0;
int totaly = 0;
for (int j=0; j<moves.size(); j++){
if (moves.get(j).equals("up")) {
Animation animation = new TranslateAnimation(0, 0 , 0, -(63+totaly));
animation.setDuration(1000);
animation.setFillAfter(true);
circle.startAnimation(animation);
totaly = totaly - 63;
}
else if (moves.get(j).equals("down")) {
Animation animation = new TranslateAnimation(0, 0 , 0, (63+totaly));
animation.setDuration(1000);
animation.setFillAfter(true);
circle.startAnimation(animation);
totaly = totaly + 63;
}
else if (moves.get(j).equals("left")) {
Animation animation = new TranslateAnimation(0, -63 , 0, -(63+totaly));
animation.setDuration(1000);
animation.setFillAfter(true);
circle.startAnimation(animation);
totalx = totalx + 63;
}
else if (moves.get(j).equals("right")) {
Animation animation = new TranslateAnimation(0, 63 , 0, (63+totaly));
animation.setDuration(1000);
animation.setFillAfter(true);
circle.startAnimation(animation);
totalx = totalx + 63;
}
}
Upvotes: 0
Views: 64
Reputation: 12919
You'll have to use an AnimationSet
for chaining the individual Animations
.
AnimatorSet s = new AnimatorSet();
s.play(anim2).after(anim1);
This guide will help you: http://developer.android.com/reference/android/animation/AnimatorSet.Builder.html
Upvotes: 1