2013-05-21 53 views
0

如何在動畫結束後開始活動。我在xml中添加了android:oneshot =「true」,但是如何在此動畫停止後開始新的活動。我附上了下面的全部代碼。請讓我知道如何開始新的活動。如果我使用此代碼而不顯示我的動畫,它會轉到另一個活動。如何在幀結束後按照幀結束進行另一項活動android動畫

public class MainActivity extends Activity { 

ImageView iv; 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

} 
public void onWindowFocusChanged (boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 
     AnimationDrawable animation = (AnimationDrawable) iv.getBackground(); 

     if(hasFocus) {   
      animation.start(); 
       startActivity(new Intent(MainActivity.this,second.class)); 

     } else { 
      animation.stop(); 

     } 

    } 
public void onStart() { 
    { 
     super.onStart(); 

     iv = (ImageView)findViewById(R.id.imageView1); 
     iv.setBackgroundResource(R.animator.animation); 

    } 
} 

}

回答

1

一個肯定的方式,可以使用onAnimationListener,並真正感興趣到實現偵聽器接口的onAnimationEnd方法。

事情是這樣的:

animation.setAnimationListener(new Animation.AnimationListener() { 
       @Override 
       public void onAnimationStart(Animation animation) { 

       } 

       @Override 
       public void onAnimationEnd(Animation animation) { 
       startActivity(new Intent(MainActivity.this,second.class)); 
       } 

       @Override 
       public void onAnimationRepeat(Animation animation) { 

       } 
      }); 
+0

我使用AnimationDrawable。 –

+0

對不起,檢查這個問題,它給你很多選擇這樣做:http://stackoverflow.com/questions/2214735/android-animationdrawable-and-knowing-when-animation-ends –

+0

tnx的鏈接它真的幫我一個很多:) –