How to start activity on animation end

前端 未结 2 1917
予麋鹿
予麋鹿 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:41

    Set an AnimationListener to the animation you want to use to start your Activity.

    myAnimation.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {}
        public void onAnimationRepeat(Animation animation) {}
        public void onAnimationEnd(Animation animation) {
            Intent i = new Intent( LineageSplashActivity.this, LineageMenuActivity.class );
            LineageSplashActivity.this.startActivity( i );
        }
    }
    

    So, your code will be like this:

    package com.lineage.goddess;
    
    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.AnimationUtils;
    import android.widget.TextView;
    
    public class LineageSplashActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            startAnimation();
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    
        }
    
        private void startAnimation() {
            // TODO Auto-generated method stub
            TextView logo1= (TextView) findViewById(R.id.TextView1);
            Animation fade1= AnimationUtils.loadAnimation(this, R.anim.fade_in);
            logo1.startAnimation(fade1);
            TextView logo2= (TextView) findViewById(R.id.TextView2);
            Animation fade2= AnimationUtils.loadAnimation(this, R.anim.fade_in);
            logo2.startAnimation(fade2);
            TextView logo3= (TextView) findViewById(R.id.TextView3);
            Animation fade3= AnimationUtils.loadAnimation(this, R.anim.fade_in);
            logo3.startAnimation(fade3);
            TextView logo4= (TextView) findViewById(R.id.TextView4);
            Animation fade4= AnimationUtils.loadAnimation(this, R.anim.fade_in2);
            face4.setAnimationListener(new AnimationListener() {
                public void onAnimationStart(Animation animation) {}
                public void onAnimationRepeat(Animation animation) {}
                public void onAnimationEnd(Animation animation) {
                    Intent i = new Intent( LineageSplashActivity.this, LineageMenuActivity.class );
                    LineageSplashActivity.this.startActivity( i );
                }
            }    
    
            logo4.startAnimation(fade4);    
        }
    }
    

提交回复
热议问题