2011-10-06 90 views
6

在我的項目中,我有一個按鈕。當用戶點擊它時,它顯示並且動畫之後應該加載另一個活動。Android,我怎麼知道動畫完成?

@Override 
    public void onClick(View v) { 
     switch (v.getId()){ 
      case R.id.btnReadPage: 
       startAnimation(); 
       //stopAnimation(); 
       //Toast.makeText(this, "Read Page Clicked", Toast.LENGTH_SHORT).show(); 
       //startActivity(new Intent(this, ReadPage.class)); 
       return; 
     } 

    } 

根據上面的代碼(startActivity,評論),當我運行應用程序並點擊按鈕,動畫將播放。但如果我取消註釋,因爲快速過渡動畫不顯示。 我如何通知動畫完成? 感謝

+0

http://stackoverflow.com/questions/4750939/android-animation-is-not-finished-in-onanimationend –

+0

查看答案這裏。 http://stackoverflow.com/questions/2214735/android-animationdrawable-and-knowing-when-animation-ends – pierrotlefou

+0

很好的問題:) –

回答

9

在您的動畫對象調用此代碼:

am1.setAnimationListener(new AnimationListener() {  
    @Override 
    public void onAnimationStart(Animation animation) { 
     // TODO Auto-generated method stub 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 
     // TODO Auto-generated method stub 
    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
     // Pass the Intent to switch to other Activity 

    } 
}); 
相關問題