2011-01-11 9 views
1

나는 게임 응용을 쓴다. 사용자가 잘못된 버튼을 누르면 애니메이션을 표시하고 애니메이션이 완료되면 게임을 마칩니다.android는 활동이 끝나기 전에 애니메이션이 끝날 때까지 기다린다.

현재 완성 된 애니메이션이 시작되면 애니메이션이 시작됩니다. 애니메이션이 완성되기를 바래요. 다음은

이이 내 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; 
     } 

애니메이션을 시작 내 주요 활동 방법입니다 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); 

    } 
} 

답변

0

'애니메이션'이 무엇인지 구체적으로 설명 할 수 있습니까? 프레임을 직접 재생하거나 이미지 또는 비디오 만 재생하는 수업입니까?

가장 좋은 방법은 콜백 메서드를 만들고 애니메이션이 끝날 때 실행하는 것입니다. 이 같은

+0

가 내 주요 활동에서 애니메이션을 시작하고있다. 나는 애니메이션과 애니메이션 리스너를위한 커스텀 클래스를 사용하고있다. 나는 애니메이션을 http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html에서 예제를 수정했다. 애니메이션은 이미지입니다. 사용자가 버튼을 클릭하고 "대답"이 틀리면 카드가 뒤집혀 자신의 결과가 잘못되었음을 표시 한 다음 작업을 끝내고 싶습니다. 그러나 애니메이션이 완료되기 전에 내 활동이 끝납니다. 또한 사용자가 오른쪽 버튼을 클릭하면 올바른 결과를 나타내는 카드와 동일한 애니메이션이 나타납니다. – SingleMalt

+0

당신은 애니메이션 리스너를 사용하고 있다고 말하고 있습니다. AnimationListener의 onAnimationEnd() 콜백을 사용하고 있습니까? 당신이하고있는 것을 정확히 볼 수있는 몇 가지 예제 코드가 필요합니다. 귀하의 답변과 모든 도움에 감사드립니다. =/ – Nick

+0

감사합니다. 내 질문을 업데이트하고 코드에 추가했습니다. 네가 필요한 것이 있으면 알려줘. – SingleMalt

0

뭔가 :

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; 
} 
관련 문제