2

I want to show a progress bar at the end of the list when loading more data using RecyclerView. Just for the sake of the test I set it to always visible but it's not visible at all. I tried to put it inside a LinearLayout but that wasn't helpful.

Here is my fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/latestnews_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_latestnews"
            android:scrollbars="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </android.support.v4.widget.SwipeRefreshLayout>
    <ProgressBar
        android:id="@+id/loadmore_progressBar"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:indeterminate="true"
        android:layout_gravity="center"
        android:visibility="visible" />
</LinearLayout>

Fragment is loaded inside a viewpager:

        <LinearLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <android.support.design.widget.TabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
        </LinearLayout>
Vahid Amiri
  • 10,522
  • 12
  • 59
  • 102
  • Of course it's not visible, you're not allowing it to be visible when you set the `recyclerView` to `fill_parent` – Pztar Jan 26 '16 at 16:52
  • @Pztar, I changed the recyclerview to `wrap_content` and the progressbar is still not visible. – Vahid Amiri Jan 26 '16 at 16:55
  • You can't do that. Set your `RefreshLayout` to a set height like `300dp` you'll see your progress bar then – Pztar Jan 26 '16 at 17:00
  • @Pztar Setting it to a hard coded number is useless and not what I want. Is there any way to show progressbar on top of the recyclerview?? – Vahid Amiri Jan 26 '16 at 17:02
  • It's an example, you can set it to whatever you want. I don't know how `SwipeRefereshLayout` works so I can't give you exact details but if you had it in a `RelativeLayout` for example you can set it relative to another `View` actually I'm sure if you change your root layout to a `RelativeLayout` you can have far more control over the placements of your `Views` – Pztar Jan 26 '16 at 17:09
  • 1
    Also as a side note `fill_parent` is deprecated use `match_parent` instead it does the same thing, and don't use `px` values use `dp` – Pztar Jan 26 '16 at 17:11

2 Answers2

4

If you change to your root layout to RelativeLayout then it's fairly simple:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25dp"
android:minHeight="25dp">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/latestnews_swipe_refresh_layout"
    android:layout_above="@id/loadmore_progressBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView_latestnews"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>

<ProgressBar
    android:id="@+id/loadmore_progressBar"
    android:layout_width="45dp"
    android:layout_height="45dp"
    android:indeterminate="true"
    android:visibility="visible"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"/>
</RelativeLayout>

In my opinion though, I'd put the ProgressBar in the RecyclerView though the adapter, it looks much nicer but the chocie is yours.

Pztar
  • 3,484
  • 5
  • 29
  • 39
0

The height of the RecyclerView can't be set as wrap_content as stated in this question, so it is not giving any space left to show the ProgressBar. You need to set up a custom LayoutManager to do that.

You have a few examples also in this other question, it seems to just tackle your problem.

Community
  • 1
  • 1
Evin1_
  • 10,198
  • 8
  • 38
  • 47