如何增加启动画面的计时器?

时间:2013-06-19 06:02:53

标签: android

如何增加启动画面的计时器?我需要它慢一些。

public class MainActivity extends Activity {

private Handler mHandler = new Handler();

ImageView imageview;
int alpha = 255;
int b = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageview = (ImageView) this.findViewById(R.id.imageView1);     

    imageview.setAlpha(alpha);

    new Thread(new Runnable() {
        public void run() {
            initApp();

            while (b < 2) {
                try {
                    if (b == 0) {
                        Thread.sleep(1000);
                        b = 1;
                    } else {
                        Thread.sleep(50);
                    }

                    updateApp();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }).start();

    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            imageview.setAlpha(alpha);
            imageview.invalidate();

        }
    };

}

public void updateApp() {
    alpha -= 5;

    if (alpha <= 0) 
        {
            b = 2;          
            Intent in = new Intent(this, TabsLayoutActivity.class);
            startActivity(in);
            this.finish();
        }
    mHandler.sendMessage(mHandler.obtainMessage());

}   
public void initApp(){       

}

  }

2 个答案:

答案 0 :(得分:1)

您也可以像下面一样使用处理器作为启动画面。

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            finish();
            Intent menu = new Intent(getBaseContext(), MainMenu.class);
            startActivity(menu);
        }
    }, 3000);

这里3000 = 3秒。你可以根据需要更换时间。希望它可以帮到你。

答案 1 :(得分:0)

增加睡眠时间

 Thread.sleep(3000);  /// 3000 milli seconds i.e 3 sec 

如果你想要更多只是增加这个数字。