center text in a listview

前端 未结 2 1780
北恋
北恋 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.


    
    

提交回复
热议问题