私はゲームアプリケーションを作成しています。ユーザーが間違ったボタンを押した場合、私はアニメーションを表示したい。アニメーションが完了したら、ゲームを終了する。Androidがアクティビティが終了する前にアニメーションが終了するのを待ちます。
現在のところ、私のアニメーションは仕上げが呼び出されたときに始まります。私はアニメーションを完成させたい。以下は
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) {
}
}
これはこれはこれはスレッド
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);
}
}
である私のSwapViewクラスでアニメーション
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;
}
を開始し、私の主な活動方法であるが実装私のクラスであります
私は私の主な活動からアニメーションを始めています。私は、アニメーションとアニメーションのリスナーのためのカスタムクラスを使用しています。アニメーションについては、例をhttp://www.inter-fuser.com/2009/08/android-animations-3d-flip.htmlから変更しました。アニメーションはイメージです。 ユーザーがボタンをクリックし、「回答」が間違っていると、結果が間違っていることを示すためにカードが反転し、その後、アクティビティを終了します。しかし、私の活動はアニメーションが完了する前に終了します。また、ユーザーが右ボタンをクリックすると、正しい結果を示すカードと同じアニメーションが表示されます。 – SingleMalt
アニメーションリスナーを使用しているとします。 AnimationListenerのonAnimationEnd()コールバックを使用していますか?私は何をしているのかを正確に見るためにいくつかのサンプルコードが必要です。あなたの応答とすべての助けを感謝して=/ – Nick
を推測するのは難しいです。私は自分の質問を更新し、コードに追加しました。あなたが何か他のものが必要な場合は教えてください。 – SingleMalt