Android的等待动画活动之前完成结束
问题描述:
我写一个游戏应用。如果用户按错了按钮,我想显示一个动画,当动画完成时,完成()我的游戏;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) {
}
}
这是我的一个启动动画
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);
}
}
答
你能更具体,这是什么“动画”是什么?这是一个你自己玩框架或只是图像或视频的课程吗?
,如果它是第一个最好的方法是创建一个回调方法,只是火,当动画完成。
答
事情是这样的:
public final class DisplayNextView implements Animation.AnimationListener {
View changeView;
Drawable image;
boolean mIsCorrect;
Activity mContext;
public DisplayNextView(View parChangeView, Drawable parImage,
boolean isCorrect, Activity context) {
this.changeView = parChangeView;
this.image = parImage;
mIsCorrect = isCorrect;
mContext = context;
}
public void onAnimationStart(Animation animation) {
changeView.post(new SwapViews(changeView, image));
changeView.postDelayed(new SwapViews(changeView, null), 1000);
}
public void onAnimationEnd(Animation animation) {
if (mIsCorrect == false) {
mContext.finish();
}
}
public void onAnimationRepeat(Animation animation) {
}
}
和你applyRotation应该通过猜测是否是正确的:
private void applyRotation(View parChangeView, Drawable image, float start,
float end, boolean isCorrect) {
// 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, isCorrect, this));
parChangeView.startAnimation(rotation);
// return rotation;
}
我开始从我的主要活动的动画。我使用动画和动画侦听器的自定义类。我为动画修改了http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html中的示例。动画是一个图像。 用户点击一个按钮,如果“答案”是错误的,那么卡翻转,以显示他的结果是错误的,然后我要完成的活动。但是,我的活动在动画完成之前完成。另外,当用户点击右键时,卡片上显示相同的动画,显示正确的结果。 – SingleMalt 2011-01-13 14:37:00