2016-09-14 2 views
1

アクティビティが開始されるとすぐにアニメーションを開始したいと思います。そして、アニメーションが終了するとすぐに、別のアクティビティを開始したいので、私は多くを検索し、誰もがonAnimationEnd()を使用することを推奨しました。ただし、コードを実行すると、アニメーションが終了した後に新しいアクティビティは表示されません。誰かが私のエラーを指摘できますか?ここで アニメーションの終了後にアクティビティを変更するにはどうすればよいですか?アニメーションリスナーが動作していないようです

は私のMainActivity.java

public class MainActivity extends AppCompatActivity implements Animation.AnimationListener { 
TextView ticTacToe; 
Animation animation; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ticTacToe = (TextView) findViewById(R.id.tictactoe); 
    //bounce is the xml animation file 
    animation= AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.bounce); 
} 

@Override 
public void onWindowFocusChanged(boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 
    if (hasFocus) 
     ticTacToe.startAnimation(animation); 
} 

@Override 
public void onAnimationStart(Animation animation) { 

} 

@Override 
public void onAnimationEnd(Animation animation) { 
    Intent intent = new Intent(this,Main2Activity.class); 
    startActivity(intent); 
} 

@Override 
public void onAnimationRepeat(Animation animation) { 

} 
} 
+0

はあなたの開始アニメーションが動作していますか? –

+0

はい。それは完全に動作しています –

答えて

1

で、あなたのonWindowFocusChangedでこれを行いますので、あなたの現在のウィンドウがフォーカスを取得するが、リスナーがまだあなたのanimation

animation.setAnimationListener(new AnimationListener() { 
     public void onAnimationStart(Animation animation) {} 
     public void onAnimationRepeat(Animation animation) {} 
     public void onAnimationEnd(Animation animation) { 
       Intent intent = new Intent(MainActivity.this,Main2Activity.class); 
       startActivity(intent); 
     } 
    }  

    ticTacToe.startAnimation(animation) 
に接続されていないアニメーションを開始します

またはこれも可能ですoncreate

animation.setAnimationListener(this);

+0

ありがとうございます。出来た! –

+0

あなたの歓迎buddy.happyコーディング –

関連する問題