0
私はeclipesを使用してアンドロイドカードゲームを作成しています。アニメーションを呼び出すと何らかの理由でアプリケーションがクラッシュします。私がしなければならなかった変更の1つはFlipクラスで、それはアニメーションメソッド "createDisplayNextView"にエラーがあったため、layoutviewをimageviewに変更していました。Androidの3Dフリップアニメーション
////////ANIMATION
private ImageView FrontView;
private ImageView BackView;
private boolean isFirstImage = true;
private void applyRotation(float start, float end) {
// Find the center of image
FrontView = (ImageView) findViewById(R.id.imgC1);
BackView = (ImageView) findViewById(R.drawable.clubs2);
BackView.setVisibility(View.GONE);
final float centerX = FrontView.getWidth()/2.0f;
final float centerY = FrontView.getHeight()/2.0f;
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final cardFlip rotation = new cardFlip(start, end, centerX, centerY);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(rotation.createDisplayNextView(isFirstImage, FrontView, BackView));
if (isFirstImage) {
FrontView.startAnimation(rotation);
} else {
BackView.startAnimation(rotation);
}
}
///////////////
これはフリップクラスです:
////////////////FLIP CLASS//////////////
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class cardFlip extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private Camera mCamera;
public cardFlip(float fromDegrees, float toDegrees, float centerX, float centerY) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
}
public DisplayNextView createDisplayNextView (boolean isFirstImage, ImageView llFrontView, ImageView llBackView)
{
return new DisplayNextView(isFirstImage,llFrontView, llBackView);
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
public final class DisplayNextView implements Animation.AnimationListener {
private boolean mCurrentView;
ImageView image1;
ImageView image2;
public DisplayNextView(boolean currentView, ImageView llFrontView, ImageView llBackView) {
mCurrentView = currentView;
this.image1 = llFrontView;
this.image2 = llBackView;
}
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
image1.post(new SwapViews(mCurrentView, image1, image2));
}
public void onAnimationRepeat(Animation animation) {
}
public final class SwapViews implements Runnable {
private boolean mIsFirstView;
ImageView image1;
ImageView image2;
public SwapViews(boolean isFirstView, ImageView image12, ImageView image22) {
mIsFirstView = isFirstView;
this.image1 = image12;
this.image2 = image22;
}
public void run() {
final float centerX = image1.getWidth()/2.0f;
final float centerY = image1.getHeight()/2.0f;
cardFlip rotation;
if (mIsFirstView) {
image1.setVisibility(View.GONE);
image2.setVisibility(View.VISIBLE);
image2.requestFocus();
rotation = new cardFlip(90, 0, centerX, centerY);
} else {
image2.setVisibility(View.GONE);
image1.setVisibility(View.VISIBLE);
image1.requestFocus();
rotation = new cardFlip(-90, 0, centerX, centerY);
}
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
if (mIsFirstView) {
image2.startAnimation(rotation);
} else {
image1.startAnimation(rotation);
}
}
}
}
}
アプリが強制終了している場合は、ログが非常に役立ちます。 – adneal