ListView从底部而不是从顶部填充

时间:2012-11-07 12:57:49

标签: android android-layout listview

我有一个向上扩展而不是向下扩展的listView。 我在另一个页面上有另一个listView,它工作正常并从顶部填充自己 - >机器人。 为什么我的listView从底部开始而不是从顶部开始?

我的XML `

<ListView
    android:id="@+id/list_view_showRegister"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/showRegister"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="50dp"
    android:clickable="false" >

</ListView>`

3 个答案:

答案 0 :(得分:28)

您的ListView实际上仍在从上到下填充。只是不是从页面的顶部。

您已设置layout_height="wrap_content"layout_above="@+id/showRegister"。如果高度为wrap_content,则视图将仅与其内容一样大。然后,由于您使用了layout_above这一事实,它将直接位于另一个视图之上。

列表视图不是从底部填充,而是从列表视图的顶部填充 - 但列表视图本身仅从屏幕的中间开始。列表视图上方的任何内容实际上并不是listview 的一部分,而是空白空间。

解决方案是设置layout_height="match_parent",或删除layout_above代码。

我知道这是一个老问题,但我希望这可以帮助其他任何可能通过谷歌找到此问题的人。

答案 1 :(得分:8)

请参阅android:stackFromBottom属性。

答案 2 :(得分:8)

看看这些链接。 Is it possible to make a ListView populate from the bottom?。从底部填充。 Add new items to top of list view on Android?。在列表顶部添加新项目。

相关问题