显示ImageView为秒,然后隐藏线程

时间:2012-07-04 03:54:28

标签: android multithreading android-imageview

我需要先显示ImageView,然后在menuInflater中单击时使用Thread隐藏。

例如:

    public boolean onOptionsItemSelected(MenuItem item) {

    super.onOptionsItemSelected(item);

    switch (item.getItemId()){

    case R.id.txt1:
        handler = new Handler (this);
                    Worker w = new Worker (handler);
                   Thread t = new Thread (w);
                   t.start();
         return true;

你的意思是这样吗?

 protected int [] imgIds = {
        R.id.img_1,R.id.img_2,R.id.img_3,R.id.img_4,R.id.img_5,R.id.img_6,
        R.id.img_7,R.id.img_8,R.id.img_9,R.id.img_10,R.id.img_11,R.id.img_12,
};

    public class Worker implements Runnable{

private Handler h;

public Worker (Handler h)
{
    this.h = h;
}

@Override
public void run() {

    for(int i=0; i<10; i++)
    {
        imgIds.setsetVisibility(View.INVISIBLE)

        try{
            Thread.sleep(1000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
    h.postDelayed(Worker,1000);

}   

}

然后ImageView隐藏并启动游戏。

1 个答案:

答案 0 :(得分:0)

@Override
public void run() {

    for(int i=0; i<10; i++)
    {
        imgIds.setsetVisibility(View.INVISIBLE)

        try{
            Thread.sleep(1000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
     Intent intent = new Intent();
     intent.setClass(sPlashScreen.this,Next.class);
     startActivity(intent);
     stop()
}   

}