5

プログラム用に簡単なアニメーションを作成したいと思います。目に見えないボタンが4つあり、プログラムが開始されると、それらのボタンが遅れて表示されるようになります。

ボタン 1 を表示 -> ボタン 2 -> など。

これを試してみましたが、プログラムを実行すると、すべてのボタンが同時に表示されます。

try {
((Button) findViewById(R.id.f1)).setVisibility(View.VISIBLE);
    Thread.sleep(1200);
((Button) findViewById(R.id.f2)).setVisibility(View.VISIBLE);
    Thread.sleep(1200);
((Button) findViewById(R.id.f3)).setVisibility(View.VISIBLE);
    Thread.sleep(1200);
((Button) findViewById(R.id.f4)).setVisibility(View.VISIBLE);
    Thread.sleep(1200);
 } catch (Exception e) {
 }

誰でも私を助けることができますか?

4

2 に答える 2

9

ハンドラーを使用します。

private Handler handler;

private void showButtons(){
    handler = new Handler();

handler.postDelayed(new Runnable(){
    @Override
    public void run(){
        ((Button) findViewById(R.id.f1)).setVisibility(View.VISIBLE);
    }
}, 1200);

handler.postDelayed(new Runnable(){
    @Override
    public void run(){
        ((Button) findViewById(R.id.f2)).setVisibility(View.VISIBLE);
    }
}, 2400);

//etc
}
于 2012-07-01T12:19:58.970 に答える
0

これはこの質問とは関係ありませんが、メインスレッドをスリープ状態にすると(あなたがしていることと同じように)、アプリケーションがフリーズする可能性があります

于 2012-07-01T12:25:05.483 に答える