Home » Android » android – ContentLoadingProgressBar is not displaying for a minimum amount of time before hiding-Exceptionshub

android – ContentLoadingProgressBar is not displaying for a minimum amount of time before hiding-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I’m trying to use ContentLoadingProgressBar to display 1 second before hiding itself. However I can’t seem to find any examples of how to use it correctly with a recyclerview.

So I’ve tried using just testing it, but I can’t get it to display for a minimum amount of time. How would I do so?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.ContentLoadingProgressBar
        android:id="@+id/main_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        style="?android:attr/progressBarStyleLarge"
        android:visibility="visible"/>

</RelativeLayout>

I’ve simply just tried doing it like this:

mProgressBar.show();
mProgressBar.hide();

However it’s not displaying for 1 second before hiding. It just hides automatically.

How to&Answers:
mProgressBar.show();
Handler().postDelayed({
  mProgressBar.hide();
}, 1000)

Answer:

ContentLoadingProgressBar has minimum threshold time 500ms, so you should wait this time before hiding

Answer:

ContentLoadinProgressBar is built to prevent flickering of UI during frequent show hide calls of progressBar. So if you quickly call hide(); after calling show(); then it’ll ignore the show();. which is normal. to prevent flickering.

Have a look at Charuක’s Answer