2012-03-23 6 views
0

나는 안드로이드 카드 게임을 만드는 eclipes를 사용하고 있습니다. 애니메이션을 호출 할 때 어떤 이유로 인해 어플리케이션이 다운됩니다. 플립 클래스에 한 가지 변경 사항이 있었고 애니메이션 메서드 "createDisplayNextView"에 오류가 있었기 때문에 layoutview를 imageview로 변경했습니다. 안드로이드 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); 
     } 
    } 
} 
    } 

    } 
+0

앱을 강제 종료하는 경우 로그가 매우 유용합니다. – adneal

답변

0

..

public class SplashActivity extends Activity { 
    // protected boolean _active = true; 
    protected int _splashTime = 5000; 
    private ImageView imag; 
    AnimationDrawable frameAnimation ; 


    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.splashactivity); 
     imag = (ImageView) findViewById(R.id.splashactivity_imag); 

     imag.setBackgroundResource(R.drawable.splash_animation); 

      frameAnimation = (AnimationDrawable) imag 
       .getBackground(); 

      Thread splashTread = new Thread() { 
       public void run() { 
        try { 
         sleep(_splashTime); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } finally { 
         Intent intent; 
         intent = new Intent(SplashActivity.this, HomeActivity.class); 
         startActivity(intent); 
         finish(); 
        } 
       } 
      }; 
      splashTread.start(); 
     } 

    @Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
     super.onWindowFocusChanged(hasFocus); 
     frameAnimation.start(); 

    } 

} 

당김이 새로운 XML을 만들 ...

splash_animation.xml

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 

    android:oneshot="true" > 

    <item 
     android:drawable="@drawable/ac" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/ab" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/aa" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/z" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/y" 
     android:duration="200"/> 
    <item 
     android:drawable="@drawable/x" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/w" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/v" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/u" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/t" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/s" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/q" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/p" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/n" 
     android:duration="300"/> 
<item 
     android:drawable="@drawable/o" 
     android:duration="300"/> 
<item 
     android:drawable="@drawable/m" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/l" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/k" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/j" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/i" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/h" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/g" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/f" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/e" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/d" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/c" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/b" 
     android:duration="200"/> 
<item 
     android:drawable="@drawable/a" 
     android:duration="200"/> 


</animation-list>