Android动画转向
我使用下面的代码在一系列中转弯(向左或向右)。所以如果我一个接一个地叫它,即:Android动画转向,android,rotateanimation,Android,Rotateanimation,我使用下面的代码在一系列中转弯(向左或向右)。所以如果我一个接一个地叫它,即:turn(90);转(90);转弯(-90)它显示的是最后一个。我想展示给大家看,等到第一个完成后再继续下一个。有什么想法吗 public void turn(int i) { RotateAnimation anim = new RotateAnimation( currentRotation, currentRotation + i,
turn(90);转(90);转弯(-90)代码>它显示的是最后一个。我想展示给大家看,等到第一个完成后再继续下一个。有什么想法吗
public void turn(int i)
{
RotateAnimation anim = new RotateAnimation( currentRotation, currentRotation + i,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
currentRotation = (currentRotation + i) % 360;
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setFillAfter(true);
token.startAnimation(anim);
}
所以我所做的就是创建一个动画和一个迭代器来运行它。。。在我定义了所有需要完成的动画并将它们添加到que之后,我运行了第一个动画,然后在AnimationListener中处理其余的动画
Queue<RotateAnimation> que = new LinkedList<RotateAnimation>();
Iterator<RotateAnimation> queIt;
public void turnToken(int i){
RotateAnimation anim = new RotateAnimation( currentRotation, currentRotation + i,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
currentRotation = (currentRotation + i) % 360;
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setAnimationListener(this);
anim.setFillAfter(true);
que.add(anim);
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
if(queIt.hasNext()){
token.startAnimation((Animation) queIt.next());
}
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}