How to set footer in android list to dynamically stretch to bottom?

I have already searched, but, unfortunately, have not found a real solution to this. I added a footer to the list view with:

View footer = getLayoutInflater().inflate(R.layout.listfooter, null); listview.addFooterView(footer); 

The XML for the footer is as follows:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/footer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#FFFFFFFF" android:orientation="vertical" android:layout_alignParentBottom="true" android:background="#ee222222" > <TextView android:id="@+id/info" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Test Test Test" android:layout_alignParentBottom="true" android:layout_gravity="center_vertical" /> </LinearLayout> 

It displays the footer as a single line only

I am changing the number of lines in the list dynamically, but I want the footer to always fill the rest of the list if there are not enough elements in it.

How can i do this?

Change: I added an image, on the left - as it is now, and on the right - 2.

+4
source share
1 answer

I can say that the best solution for this problem may be.

1) Create an XMl layout that should have such a hierarchy.

  <Liniear Layout> <ScrollView> <LinearLayout> <ListView>// add your list data here. <\ListView> <TextView><TextView>// for footer text <\LinearLayout> <ScrollView> <LinearLayout> 

Please let me know if anything, I hope this approach will work as I tried it myself.

0
source

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


All Articles