引用:http://www.cnblogs.com/vir56k/archive/2011/06/28/2092176.html
package com.androidGreenPack.tools;
import android.content.Context;
import android.os.Handler;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* 显示logo界面,倒计时n秒后,进入下一个页面
* **/
public class LogoShow extends LinearLayout{
private Context mContext;
private int _number;
private TextView textView;
private Handler handler;
public LogoShow(Context context){
super(context);
mContext = context;
}
public void addLogoShow(){
textView = new TextView(mContext);
textView.setText("成功");
this.addView(textView);
//传递一个Runnable对象,1秒后执行该对象的run方法
handler = new Handler();
handler.postDelayed(run1,1000);
}
//执行的代码
private Runnable run1 = new Runnable(){
public void run() {
String text = "";
text = ""+_number++;
textView.setText(text);
//再次传递一个Runnable对象,类似产生一种递归效果
handler.postDelayed(run1,1000);
if(_number == 10){
//移除回调
handler.removeCallbacks(run1);
textView.setText("跳转");
}
}};
}