简体   繁体   中英

how to show images after a short time in android

i want to show images with delay after a button click

       final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            // Do something after 5s = 5000ms

        }
    }, 26000);

i want to use this code for this actualy,i want to show this images(on a motion layout) 在此处输入图像描述

after 26s of clicking this button在此处输入图像描述

You already have your Handler and postDelayed method. Create the ImageView you want to show, default visibility as GONE or INVISIBLE and inside the postDelayed method, set it to VISIBLE.

Maybe I didn't understand your question correctly, but it seems that you already answered your own question.

Let me share some code. In your XML file, you'll have an ImageView and set the visibility property.

<ImageView
     android:id="@+id/yourImage"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone" />

In your Activity, you'll first find and create a reference to the ImageView and then change its visibility property after the delay.

ImageView yourImage = findViewById(R.id.yourImage);

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        yourImage.setVisibility(View.VISIBLE);
    }
}, 26000);

By default, your image will not show because it's set to GONE in the XML. The handler will execute the code inside the run method after 26s, then your image visibility property will be set to VISIBLE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM