简体   繁体   中英

Android ListView items aligned on top

I have an 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" >

Sometimes it contains only a few items, sometimes just one.

When this is the case, these few items are centered on the listview. But I want the items start from the top and not be centered.

How to do it?

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

above 2 lines made your listview to center of its parent.hence you got items are centered on the listview.

Can you remove android:layout_centerVertical="true" from your code and try again?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM