Fading Background then Go to Next Activity

谁都会走 提交于 2019-12-11 10:05:34

问题


I just wanted to imitate famous games like Angry Birds wherein when you start the game, there are couple of screens, flashing then fading out, then go to another screen, fades out then the main menu comes out. How do i do that? Currently my code is this for the fading in and out. After implementing the code below, surprisingly, it did not animate. Any idea guys?

package com.kfc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Intro extends Activity {
    LinearLayout screen;
    Handler handler = new Handler();
    int i;
    Intent intent;
    TextView tv;
    Animation mAnim;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.introxml);

        screen = (LinearLayout) findViewById(R.id.myintro);


        Animation fade = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        fade.setAnimationListener(new AnimationListener() {
            @Override
             public void onAnimationRepeat(Animation animation) {
              // TODO Auto-generated method stub

             }
            @Override
             public void onAnimationStart(Animation animation) {
              // TODO Auto-generated method stub

             }
            @Override
             public void onAnimationEnd(Animation animation) {
                startActivity(new Intent(Intro.this, NewKFCActivity.class));
                Intro.this.finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
             }

        });
        screen.startAnimation(fade);

    }
}

回答1:


This can be done with activity animations.

Just after invoking startActivity, call

overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

The first argument means that the activity you are about to start is going to fade in, the second argument specifies a fade-out animation for the activity that is currently in the foreground.



来源:https://stackoverflow.com/questions/8049917/fading-background-then-go-to-next-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!