1

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:

Extra margin on bottom of footer list

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).

1st list doesn't stretch to fully cover 2st 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?

iliask
  • 535
  • 2
  • 7
  • 18
  • 1
    Is there any specific reason to display the 2nd list view as footer? It can be aligned bottom of first list view..right? – Kameswari Dec 12 '13 at 10:00
  • Keep your footer part into separate layout. Also remove the second listview from your footer layout. – GrIsHu Dec 12 '13 at 10:01
  • Yes, I want to scroll to the bottom of the first list and then show the TextView and footer list. The LinearLayout is in another file called myfooter.xml. – iliask Dec 12 '13 at 10:25

1 Answers1

0

I don't think you can embed a second list within the footer of your ListView, and I think this is the source of your problem. It is common to have issues when embedding multiple scrollable views within the same view (or screen).

Move the second listview out of your footer, and I think it will display correctly - I don't think you can embed it in your footer.

Booger
  • 18,579
  • 7
  • 55
  • 72
  • Please see update 2. Sure this will work no doubt, but the problem with this is I have to fix the 2nd list to take a particular size of the initial screen (the scrolling to it feature cannot work because I would have to wrap it in a ScrollView which is bad). – iliask Dec 12 '13 at 13:05
  • This is specifically addressed all over SO. The issue, is you can not have multiple scrollable items in a single scroll view (like your multiple lists). (http://stackoverflow.com/questions/16515879/multiple-listviews-inside-a-scrollview). – Booger Dec 12 '13 at 13:18
  • For all intends and purposes I don't want the scrolling of the 2nd list as it is pointless since the first list will scroll through everything. So in that sense, it is not like the other questions which require the inner-scrolling of the listview inside the scrollview. I have tried to compute the height of the list dynamically based on it's children but it is not 100% accurate as not all items have the same height. – iliask Dec 12 '13 at 14:10