want to start activity after completion of animati

2019-03-01 00:14发布

问题:

I want to rotate imageview and then I want to start activity onClick of imageview but the problem is that android system doesn't give the time to complete the animation and launching the activity. So how can I show the animation completely and then calling the activity. This is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromDegrees="-7"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatMode="reverse"
    android:toDegrees="7" />

And this code:

      public void onImageViewClicked(View view){
        switch(view.getId()){
            case R.id.viewstock:
                Animation shakeV = AnimationUtils.loadAnimation(this,     R.anim.shake);
                view.startAnimation(shakeV);
                startActivityForResult(intent, 12);
                break;
            case R.id.about:
                Animation shakeA = AnimationUtils.loadAnimation(this,     R.anim.shake1);


                 view.startAnimation(shakeA);
            Intent aboutIntent = new Intent(MainActivity.this,AboutActivity.class);
            startActivity(aboutIntent);
            break;
    }
}

回答1:

Yup, My guessing was right. Use for shakeA, shakeV

shakeA.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) { // TODO Start your activity here. startActivity(aboutIntent); // Here you go. } })


回答2:

Can you provide your code snippet to support your question. So it would be much easier to know how you are handling the animation.

For now I will assume that you are using standard Animation. If that is the case use Animation.AnimationListener to listen onAnimationEnd(Animation animation). There you start your activity.

For more check this.

Hope this will help you.