Android 背景淡出后重定向到新页面

Android 背景淡出后重定向到新页面,android,background,fading,Android,Background,Fading,我希望我的应用程序在使用线程进入另一个页面之前先有一个褪色的图片。下面是我使用的代码,它对我很有效。但是,它会在线程末尾的白色页面中停止。我该怎么做才能让它在不点击任何东西的情况下进入下一个活动?或者在页面变白后,我应该使用什么代码,以便它现在进入下一个活动 package com.kfc; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import andr

我希望我的应用程序在使用线程进入另一个页面之前先有一个褪色的图片。下面是我使用的代码,它对我很有效。但是,它会在线程末尾的白色页面中停止。我该怎么做才能让它在不点击任何东西的情况下进入下一个活动?或者在页面变白后,我应该使用什么代码,以便它现在进入下一个活动

package com.kfc;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class Intro extends Activity {
    LinearLayout screen;
    Handler handler = new Handler();
    int i;
    Intent intent;
    @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);

        (new Thread(){
            @Override
            public void run(){
                for(i=0; i<255; i++){
                    handler.post(new Runnable(){
                        public void run(){
                            screen.setBackgroundColor(Color.argb(255, i, i, i));
                        }
                    });
                    // next will pause the thread for some time
                    try{ sleep(10); }
                    catch(Exception e){ break; }
                }
                for(i=255; i>0; i--){
                    handler.post(new Runnable(){
                        public void run(){
                            screen.setBackgroundColor(Color.argb(255, i, i, i));
                        }
                    });
                    // next will pause the thread for some time
                    try{ sleep(10); }
                    catch(Exception e){ break; }
                }
                startActivity(new Intent(Intro.this,NewKFCActivity.class));
            }
        }).start();
    }
}
package com.kfc;
导入android.app.Activity;
导入android.content.Intent;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.os.Handler;
导入android.view.*;
导入android.widget.FrameLayout;
导入android.widget.LinearLayout;
公开课简介扩展活动{
线性布局屏幕;
Handler=newhandler();
int i;
意图;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE);
setContentView(R.layout.introxml);
屏幕=(线性布局)findViewById(R.id.myintro);
(新线程(){
@凌驾
公开募捐{
对于(i=0;i0;i--){
handler.post(新的Runnable(){
公开募捐{
setBackgroundColor(Color.argb(255,i,i,i));
}
});
//下一步将暂停线程一段时间
试试{sleep(10);}
catch(异常e){break;}
}
startActivity(新意图(Intro.this,newkfcacActivity.class));
}
}).start();
}
}

在for循环退出后。添加启动新活动的代码

startActivity(new Intent(Intro.this,NewACtivity.class));
你需要把它放在for循环之外。如果将它放在start方法之后,它将在线程完成之前执行。您可能还需要使用Intro.this来确定“this variable”的范围。还记得在清单文件中添加新活动,如下所示:

<activity android:name=".NewActivity"/>


alpha值设置为255,这意味着不透明且不会显示背景图像。

这是否意味着在})之前。开始();?它不起作用。。它给出了一个错误“构造函数意图(新线程(){},类)未定义”,谢谢!成功了!:)我还有一个问题。。希望你能帮助我。。那么,我怎样才能从背景图片开始呢?我运行我的程序,它从黑到白开始。。我想从一张照片变成白色。。thanksi尝试了代码并将TabTester更改为Intro.this,但它强制关闭。。可能是因为FrameLayout?Tabtester只是我创建的一个测试文件。用Intro.this替换它。错误日志说什么?我发现xml文件是线性布局的,所以我将其更改为framelayout。。程序运行时,程序是从黑色背景开始的,而不是从任何答案符合您的条件时的图片(XML文件的背景)开始的。接受它,以便其他用户可以了解。这有助于其他用户找到有效的解决方案。
screen = (FrameLayout) findViewById(R.id.layout);
(new Thread(){
    @Override
public void run(){
    for(i=0; i<255; i++){
        handler.post(new Runnable(){
            public void run(){
                screen.setBackgroundColor(Color.argb(255, i, i, i));
            }
        });
        // next will pause the thread for some time
        try{ sleep(100); }
           catch(Exception e){ break; }
        }
        startActivity(new Intent(TabTester.this,NewKFCActivity.class));
    }
}).start();
screen.setBackgroundColor(Color.argb(255, i, i, i));
screen.setBackgroundColor(Color.argb(120, i, i, i));