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

有些话、适合烂在心里 提交于 2019-12-10 12:46:12

问题


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?


回答1:


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




回答2:


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!




回答3:


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"


来源:https://stackoverflow.com/questions/6918734/how-can-i-make-the-footer-of-a-listview-stretch-to-fill-the-remaining-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!