ListView Footer Width

I have a problem with the footer for a list (I cannot focus the footer).

I am using a footer for an infinite list.

The problem I am facing is that the footer does not stretch to fit the width of the list (the wrap_content method is used instead).

This is the layout of the footer:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/footer_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center" android:padding="10dp" > <ProgressBar android:id="@+id/progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:text="Loading more..." /> </LinearLayout> 

And this is how I add the footer to the list:

 View footerView; ... // Get the custom layout for footer footerView = getActivity().getLayoutInflater(). inflate(R.layout.list_footer_load_more, getListView(), false); LinearLayout footerViewLayout = (LinearLayout) footerView.findViewById(R.id.footer_layout); // Adding custom view to ListView at footer getListView().addFooterView(footerViewLayout, null, false); 

And here is the final result: (I can not send images to stackoverflow, but here is an external link to the image) http://s21.postimg.org/3zkd7pic7/listview_footer_problem.png

I tried everything to focus on the footer, but nothing worked. I hope someone can help me because it causes me some time.

Thanks.

+4
source share
1 answer

Change the layout of the footer (R.layout.list_footer_load_more) to:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/footer_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBar android:id="@+id/progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:layout_gravity="center_vertical" android:text="Loading more..." /> </LinearLayout> </RelativeLayout> 

Change your code to:

 View footerView; ... // Get the custom layout for footer footerView = getActivity().getLayoutInflater(). inflate(R.layout.list_footer_load_more, null); RelativeLayout footerViewLayout = (RelativeLayout) footerView.findViewById(R.id.footer_layout); // Adding custom view to ListView at footer getListView().addFooterView(footerViewLayout, null, false); 
+3
source

Source: https://habr.com/ru/post/1493253/


All Articles