【发布时间】:2015-10-03 05:20:04
【问题描述】:
我花了很长时间试图找出如何在继续代码之前等待动画完成。 到目前为止,我已经尝试了 while(animation.hasEnded() == False),使用 Thread.sleep,使用计时器,但似乎无法正常工作。
出现了好几次的事情是向动画添加一个动画侦听器,我已经尝试过,但不知道如何进一步推进。
我创建动画,启动动画,然后有一行代码,我只想在动画完成后执行:
Animation moveDown = allAnimStuff(duration); //creates animation
image.startAnimation(moveDown); // Start the animation
displayScore(score); // wait for animation to finish before executing this line
这里是用于创建动画的 allAnimStuff(duration) 方法:
private Animation allAnimStuff(final long duration) {
Animation moveDown = new TranslateAnimation(image.getX(), image.getX(), (-image.getHeight()), pxHeight - image.getHeight() / 2); //creates animation
moveDown.setDuration(duration);
moveDown.setFillAfter(false);
moveDown.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//some code to make it wait here?
}
@Override
public void onAnimationEnd(Animation animation) {
image.setY((pxHeight / 2 - image.getHeight()));
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
return moveDown;
}
【问题讨论】: