我正在使用动画在屏幕上移动一个对象,但动画似乎同时运行。例如,当我选择向上和向下时,对象保持不变。随着2个向上和向下移动,对象向上移动1.我希望它向上移动1,然后再向下移动1和向上移动1。有什么办法吗?这是我的代码:
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;
}
}
答案 0 :(得分:1)
您必须使用AnimationSet
来链接个人Animations
。
AnimatorSet s = new AnimatorSet();
s.play(anim2).after(anim1);
本指南将为您提供帮助:http://developer.android.com/reference/android/animation/AnimatorSet.Builder.html