I have a ListView that has a LinearLayout as its footer view that contains a TextView and a ListView initialized like so:
mylist = (ListView) findViewById(R.id.mylist);
mylistadapter = new MyListAdapter(MainView.this, info);
myfooterlistadapter = new MyListAdapter(MainView.this, info);
LinearLayout footer = (LinearLayout)getLayoutInflater().inflate(R.layout.myfooter, null);
myfooterlist = (ListView) footer.findViewById(R.id.myfooterlist);
mylist.addFooterView(footer, null, false);
mylist
is declared as:
<ListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="0dip" <!-- have also tried fill_parent without weight, same-->
android:layout_weight="1"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:cacheColorHint="#00000000"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false" />
The footer (LinearLayout is declared as):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/myfooter" >
<TextView
android:id="@+id/myfooterlabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/headermainview"
android:paddingLeft="2dip"
android:text="@string/myfootertext"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<ListView
android:id="@+id/myfooterlist"
android:layout_width="fill_parent"
android:layout_height="0dip" <!-- have also tried fill_parent without weight, same-->
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false"
android:visibility="gone"
android:background="@color/green" />
</LinearLayout>
If my footer list has items, I change the visibility on both the TextView and the footer ListView to visible.
Now, I painted the background green on the footer listview to see the problem (sorry for hiding the text but it's confidential information). As you can see, I keep getting some extra margin on the bottom of my footer list. I've tried changing from fill_parent to wrap_content to 0dip with weight=1 for the lists and the LinearLayout but none worked. As you can see, I don't have anything related to adding extra margin after the last item on the footer list. The top list has 20 items (I've scrolled to the bottom of the screen) and my footer list has 1 item only in this case:
Any ideas what's going on and how to not have this extra margin on the bottom of my footer list? Thanks!
UPDATE:
After further inspection it seems that regardless of the size of the 2nd list (I added more items to see) the height stays the same (green box always the same size). I changed to fill_parent height on the LinearLayout (no weight) and the 2nd List but still the same size. Doesn't ListView dynamically compute the height of the footer to know how big to make it?
I'm adding a new screenshot to show you more in detail that the 2nd item is cut off (the top list is not stretching to cover the entire 2nd list).
UPDATE 2:
After further investigation if I set the height of my 2nd ListView (myfooterlist) to a particular height (say 300dip) then the 1st list shows the whole 2nd list when I scroll to the bottom. If I set it to fill_parent or wrap_conent or 0dp and add layout_weight=1 then it gives me the same height as the image above for all of them. Any idea what's going on with computing the height dynamically?