Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the footer of a ListView stretch to fill the remaining space?

I have a ListView which can contain any number of items. When it uses less than the whole height of the screen I want to show a footer which fills the remaining space.

The footer is just a tiled image. I can't just set it as the background of the ListView or its container, because the list items are partially transparent and it must be the main background and not the footer visible through them.

Adding the footer view works fine if the footer is of a fixed height, but if the fixed height is more than the remaining height then the ListView scrolls unnecessarily.

Making the footer view fill_parent seems to have no effect, it's just invisible.

Putting the footer view into the parent layout also has no effect, because the ListView seems to fill the whole height unless it's given a fixed layout_height value.

Is this possible?

like image 847
Ouchdroid Avatar asked Aug 02 '11 21:08

Ouchdroid


2 Answers

Try setting the layout weight to one, or check out trying a merge view: http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html

like image 99
Noah Avatar answered Nov 10 '22 15:11

Noah


Put the ListView inside of another layout set the expand to fill the screen.

A LinearLayout works best for this.

Something like this:

<LinearLayout android:layout_height="match_parent" 
            android:layout_width="match_parent" >
    <ListView android:layout_height="match_parent" 
              android:layout_width="match_parent" >
        ...
    </ListView>
</LinearLayout>

This should fill the LinearLayout to the bottom of the screen. You can use this behavior to control how your View looks.

Hope this helps!

like image 1
Codeman Avatar answered Nov 10 '22 17:11

Codeman