21

I've replaced in my fragment simple ProgressBar with ContentLoadingProgressBar. Now fragment layout looks like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            style="@style/simple_match_parent_style">

<android.support.v4.widget.ContentLoadingProgressBar
            android:id="@+id/progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

<TextView
    android:id="@+id/txt_no_songs"
    android:text="@string/txt_no_songs"
    android:layout_centerInParent="true"
    style="@style/txt_no_songs"/>

<ListView
    android:id="@+id/list"
    android:fastScrollEnabled="true"
    android:divider="@null"
    style="@style/simple_match_parent_style"/>

</RelativeLayout>

I show this ProgressBar in onViewCreated:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    progressBar = (ContentLoadingProgressBar) view.findViewById(R.id.progress);
    progressBar.show();
    ...
}

For test purpose I've removed progressBar.hide() call to make ProgressBar appear in any case. But the problem is that my ContentLoadingProgressBar is never really shown.

Should I do something else to show ContentLoadingProgressBar? I didn't manage to find any relevant examples of using ContentLoadingProgressBar so any useful examples are also desirable. Thanks in advance.

Bersh
  • 2,789
  • 3
  • 33
  • 47
  • may you can find what you are looking for in this link http://stackoverflow.com/questions/20438751/example-usage-for-contentloadingprogressbar – Maheera Jazi Mar 09 '14 at 10:34
  • I saw this topic but I didn't find anything useful there – Bersh Mar 09 '14 at 15:34
  • You cannot use progressBar.show(); here. after onViewCreated() call, then it's call ContentLoadingProgressBar.onAttachedToWindow() look into the source code, they remove show callback here. So, the progress bar is never shown. – tarn Aug 19 '16 at 09:26

5 Answers5

31

Seems you need a style, for example...

style="?android:attr/android:progressBarStyleHorizontal"

Works for me if I put that anyway, without I never see anything.

Also consider putting it above your content (ie below in the xml)

dten
  • 2,364
  • 21
  • 28
  • 7
    It works if you change to this: `style="?android:attr/progressBarStyleHorizontal"` otherwise there will be the following compilation error: `AAPT: error: resource android:attr/android:progressBarStyleHorizontal not found.` – Luan Barbosa Jan 12 '20 at 15:27
  • You can now also use a newer style: style="@style/Widget.AppCompat.ProgressBar.Horizontal" – ConcernedHobbit Jun 05 '21 at 14:43
10

I had tried this :

<android.support.v4.widget.ContentLoadingProgressBar
        android:id="@+id/address_looking_up"
        style="?android:attr/android:progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:visibility="visible" />

But, it didn't work at Android 5.0. Some more details about ContentLoadingProgressbar should be here.

PS: Alright, the attribute of 'style' matters here. Change the style to "?android:attr/progressBarStyleLarge" and it works.

Meanwhile, the display effect of this widget depends on the Theme of your app.

1

You should add style to ContentLoadingProgressBar.

<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content"/>
0

1.SDK said that “Show the progress view after waiting for a minimum delay. If during that time, hide() is called, the view is never made visible.” 2. I think your layout should modify like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/simple_match_parent_style">
<TextView
android:id="@+id/txt_no_songs"
android:text="@string/txt_no_songs"
android:layout_centerInParent="true"
style="@style/txt_no_songs"/>

<ListView
android:id="@+id/list"
android:fastScrollEnabled="true"
android:divider="@null"
style="@style/simple_match_parent_style"/>
<android.support.v4.widget.ContentLoadingProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        style="?android:attr/progressBarStyleLarge"
        android:visibility="gone"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>
</RelativeLayout>
vanezkw
  • 11
  • 3
0

Check the ContentLoadingProgressBar.onAttachedToWindow() or ContentLoadingProgressBar.onDetachedToWindow() if you are creating multiple views at the same time, it might causing the private removeCallBacks() being called in onAttachedToWindow() or onDetachedToWindow(). Thus causing the runnable to not run, which means nothing will be displayed.

You can, for example: Simply remove private removeCallBacks() calls in onAttachedToWindow() or onDetachedToWindow(). To prevent this from happening. Don't forget to make private removeCallBacks() to public and call it in onDestroyView() for proper cleanup.

Haomin
  • 1,265
  • 13
  • 12