当前位置: 代码迷 >> Android >> 如何使android程序显示布局,然后退出几秒钟。 并显示其他布局?
  详细解决方案

如何使android程序显示布局,然后退出几秒钟。 并显示其他布局?

热度:39   发布时间:2023-08-04 09:46:35.0

嗨,大家好,我只希望该程序显示布局main0并停留几秒钟,然后显示布局main1,就像我们在任何手机中看到的程序一样,在程序开始时会出现图像或布局,然后淡出。

/**the main activity */

public class rdwt extends Activity implements OnClickListener{

Button b1;
Button b2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main0);
    //Here
    setContentView(R.layout.main1);

    b1= (Button)findViewById(R.id.Button01);
    b2= (Button)findViewById(R.id.Button02);
    b1.setOnClickListener(this);
    b2.setOnClickListener(this);


}

    public void onClick(View v) {
        if (v==this.b1){
            Intent callwrite = new Intent(this, wto.class);              
            startActivity(callwrite);
        }

        if(v==this.b2){
            Intent callread = new Intent(this, rfr.class);               
            startActivity(callread);
        }

    }

}

我认为特别是有两种不同的方法。

1)使用并发送延迟的消息

2)使用和在特定时间后更新布局

代码示例:

TimerTask bla = new YourTask();
Timer timer = new Timer();
timer.schedule(bla, 1000);

和您的类YourTask:

public class YourTask extends TimerTask {

   public void run() {
     updateYourLayout();
   }

}

编辑:但是,我认为您正在寻找启动画面。 这个简单的教程解释了如何做到这一点: :

您需要阅读有关的技术文章

//将以下行放入代码中。

   timer(3500); // Waits 3.5 seconds before moving on to the next activity.



   public void timer(int counter){ 
        new Handler().postDelayed(new Runnable(){
            @Override
            // counter is in milliseconds.
            public void run() {             
                Intent mainIntent = new Intent(THISCLASSNAME.this,CLASSNAMETOJUMPTO.class);
                startActivity(mainIntent);
                finish();  
  相关解决方案