褪色背景然后转到下一个活动 [英] Fading Background then Go to Next Activity

查看:44
本文介绍了褪色背景然后转到下一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想模仿像愤怒的小鸟这样的著名游戏,当你开始游戏时,有几个屏幕,闪烁然后淡出,然后转到另一个屏幕,淡出然后出现主菜单.我怎么做?目前我的代码是淡入淡出.在实现下面的代码后,令人惊讶的是,它没有动画.有什么想法吗?

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);

    }
}

推荐答案

这可以通过活动动画来完成.

This can be done with activity animations.

在调用startActivity之后,调用

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.

这篇关于褪色背景然后转到下一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆