How to start activity on animation end

前端 未结 2 1915
予麋鹿
予麋鹿 2021-02-08 14:00

This is my first app and i need to start new activity when the animation ends. what do I need to do? My code:

package com.lineage.goddess;

import android.app.Ac         


        
2条回答
  •  野的像风
    2021-02-08 14:44

    Your code made my eye's bleed, so I fixed it as much as I could:

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.WindowManager;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    import android.view.animation.AnimationUtils;
    
    public class LineageSplashActivity extends Activity implements AnimationListener {
    
        private static final int NUMBER_OF_ANIMATIONS = 4;
        private int animationFinishedCount = 0;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    
            startAnimations();
        }
    
        private void startAnimations() {
            Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_in);
            fade.setAnimationListener(this);    
    
            findViewById(R.id.TextView1).startAnimation(fade);
            findViewById(R.id.TextView2).startAnimation(fade);
            findViewById(R.id.TextView3).startAnimation(fade);
            findViewById(R.id.TextView4).startAnimation(fade);
        }
    
    
        @Override
        public void onAnimationEnd(Animation animation) {
                // When all animations have finished - start the next activity
            if(++animationFinishedCount == NUMBER_OF_ANIMATIONS){
                Intent intent = new Intent( this, LineageMenuActivity.class );
                startActivity( intent );
            }
        }
    
        @Override
        public void onAnimationStart(Animation animation) {
            // Nothing
        }
    
        @Override
        public void onAnimationRepeat(Animation animation) {
            // Nothing
        }
    }
    

    And if it's not a mis-type and you actually need a different animation for the 4th textview you can remove the count check and just add the animation listener to that individual animation.

提交回复
热议问题