center text in a listview

前端 未结 2 1757
北恋
北恋 2021-01-14 06:53

I\'m finding it impossible to center the text in my listview, tried wrap_content and layout_gravity=center on virtually everything vet the text doesn\'t move

here\'s

相关标签:
2条回答
  • 2021-01-14 07:44

    android:layout_gravity="center" indicates to the parent of the textview how it should be placed. This is not what you want here because a ListView ignores that attribute. Replace it with android:gravity="center". This tells the TextView how to align the text inside it, in this case center it.

    This will have no effect when your textview doesn't fill the whole space though (since the text will match the size of the view, so align doesn't change much). Since you only have a textview in each entry it makes sense to set both android:layout_width and android:layout_height to fill_parent.


    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@android:id/text1"
              android:paddingTop="10dip"
              android:paddingBottom="10dip"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:textColor="#ff000000"
              android:background="#ffffffff"
              android:gravity="center"
            />
    
    0 讨论(0)
  • 2021-01-14 07:50

    try this android:layout_centerhorizontal="true" in place of android:layout_gravity="center" in your text view

    application name center alignment in android`

    0 讨论(0)
提交回复
热议问题