开发者

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 bac开发者_StackOverflow中文版kground 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?


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


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!


Try this and tell me if it works:

  • Put the two in one parent layout (for example: Linear Layout)
  • For ListView: android:layout_hight="wrap_content"
  • For footer: android:layout_hight="fill_parent"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜