Android: centering items in a ListView

I just started learning Android and was thinking of a simple project that will help me learn.

I created a simple menu using ListView on LinearLayout.

What I want to do is the center of the text in the ListView, as well as the center of the ListView in the layout.

I tried to set gravity in the center-Hositalon, but it did not work.

+4
source share
1 answer

You can set the gravity attribute (not layout_gravity ) to the center of the text. Make sure layout_width set to "fill_parent" . For example, in my_text_view.xml :

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"/> 

And then you can use R.id.my_text_view as your resource identifier.

+6
source

Source: https://habr.com/ru/post/1343698/


All Articles