Я пишу игровое приложение. Если пользователь нажимает не ту кнопку, я хочу показать анимацию, а когда анимация завершится, закончите () мою игру;
В настоящее время моя анимация только начинается, когда вызывается готовая. Я хочу, чтобы анимация была завершена.
Ниже мой класс, который реализует AnimationListener
public final class DisplayNextView implements Animation.AnimationListener {
View changeView;
Drawable image;
public DisplayNextView(View parChangeView, Drawable parImage) {
this.changeView = parChangeView;
this.image = parImage;
}
public void onAnimationStart(Animation animation) {
changeView.post(new SwapViews(changeView, image));
changeView.postDelayed(new SwapViews(changeView, null), 1000);
}
public void onAnimationEnd(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
}
Это мой основной метод деятельности, который запускает анимацию
private void applyRotation(View parChangeView, Drawable image, float start, float end) {
// Find the center of image
final float centerX = parChangeView.getWidth() / 2.0f;
final float centerY = parChangeView.getHeight() / 2.0f;
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final Flip3DAnimation rotation =
new Flip3DAnimation(start, end, centerX, centerY);
rotation.setDuration(250);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView (parChangeView,image));
parChangeView.startAnimation(rotation);
//return rotation;
}
Это мой класс SwapView, это поток
public final class SwapViews implements Runnable {
View changeView;
Drawable image;
public SwapViews(View parChangeView, Drawable parImage) {
this.changeView = parChangeView;
this.image = parImage;
}
public void run() {
final float centerX = changeView.getWidth() / 2.0f;
final float centerY = changeView.getHeight() / 2.0f;
Flip3DAnimation rotation;
changeView.setBackgroundDrawable(image);
//TODO should find a better way!!
if (image==null)
changeView.setBackgroundColor(Color.BLACK);
rotation = new Flip3DAnimation(-90, 0, centerX, centerY);
rotation.setDuration(250);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
changeView.startAnimation(rotation);
}
}