我希望我的应用程序在使用线程进入另一个页面之前先有一个褪色的图片。下面是我使用的代码,它对我来说效果很好。但是,它在线程末尾的白页中停止。我该怎么做才能在不点击任何东西的情况下进入下一个活动?或者在页面变白后,我应该使用什么代码才能进入下一个活动?
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();
}
}