Reputation: 11117
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>
Upvotes: 3
Views: 1684
Reputation: 4749
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.
Upvotes: 4
Reputation: 12866
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.
Upvotes: 0