Question

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.

Was it helpful?

Solution

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)

OTHER TIPS

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.

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"/>

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>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top