Android ListView 项目顶部对齐

Android ListView items aligned on top

我有一个 Android ListView。

<ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myListView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" >

有时它只包含几项,有时只包含一项。

在这种情况下,这几个项目位于列表视图的中心。但我希望项目从顶部开始而不是居中。

怎么做?

android:layout_centerVertical="true"
android:layout_centerHorizontal="true"

以上 2 行使您的列表视图位于其中心 parent.hence 您得到的项目位于列表视图的中心。

你能从代码中删除 android:layout_centerVertical="true" 并重试吗?