1

サイコロを振るアプリを作成しようとしています。ボタンを押したときに結果の画像を表示し、数秒後に閉じるアクティビティを実行したいと考えています。では、どうすればこれを行うことができますか?

新しいアクティビティを呼び出さずに、アクティビティの上に画像を表示する別の方法があるでしょうか? わからない。

タイマーについていくつか読んだことがありますが、よくわかりません。そして、ユーザーがタップしてウィンドウを閉じられるようにするように言われることは知っていますが、このアプリでは、自動的に消えてほしいと確信しています。

4

5 に答える 5

4

これを使用できます:

 Timer t = new Timer();
 t.schedule(new TimerTask() {

        @Override
        public void run() {

                    image.setVisibility(View.GONE);
                    // If you want to call Activity then call from here for 5 seconds it automatically call and your image disappear....
        }
 }, 5000);
于 2013-09-11T11:27:43.187 に答える
3
new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {

                    image.setVisibility(View.GONE);
                        }
                }, 1500);
于 2013-09-11T11:17:29.727 に答える
0

ボタンをクリックした後にこれを試してみると、アクティビティは2秒後に終了します

button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                v.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        finish();

                    }
                }, 2000);

            }
        });
于 2013-09-11T12:27:23.527 に答える
0

これには多くの方法があります。

Gone/Invisible の ImageView を使用できます。後でそれを表示したい場合は、View.Visible の可視性をオンにできます。

タイマーができます。タイマーを確認し、タイマーの期限が切れたら、ImageView で必要な操作を行うことができます。別のアクティビティでオーバーロードを追加する必要があると思います。

于 2013-09-11T11:02:55.530 に答える
0

Maybe there's another way to display an image on top of my activity without calling a new activity? I'm not sure.

ダイアログを使って画像を表示することもできると思います。

I want to run an activity which displays an image of the result when a button is pressed and close it after a few seconds. So how can I do this?

CountDownTimeのを使用します。ボタンクリックで。

  mTimer = new MyTimer(timeToDisplay, interval);
  mTimer.start()

サンプルコード..

 class MyTimer extends CountDownTimer {

     //constructor for timer class
    public MyTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);

    }


   // this method called when timer is finished
    @Override
    public void onFinish() {

        //close activity or dismiss dialog here 
    }

     //this method is called for every iteration of time interval
    @Override
    public void onTick(long millisUntilFinished) {


    }

}
于 2013-09-11T11:13:48.500 に答える