0

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

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(){       

}

  }
4

2 回答 2

1

您还可以将 Handler 用于启动画面,如下所示。

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 秒。您可以根据需要替换时间。希望对您有所帮助。

于 2013-06-19T06:12:58.310 回答
0

增加睡眠时间

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

如果您想要更多,请增加该数字。

于 2013-06-19T06:07:03.560 回答