0

This may seem like a duplicate but I can't find an answer anywhere.

It seems everyone has "TextView" available to edit in their activity xml file, whereas I only have the following:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/liv1"
    android:layout_below="@+id/lt1"
    android:layout_marginTop="29dp"
    android:layout_alignRight="@+id/lt1"
    android:layout_alignEnd="@+id/lt1"
    android:layout_alignLeft="@+id/lt1"
    android:layout_alignStart="@+id/lt1"
    />

Using android:gravity = centerdoes nothing when I put it in between the "ListView" brackets.

So what is it I should do?

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
  • Text in list view cannot be centered through tags in ListView itself. If you are using a default adapter then you can't do that. You need to create a class which extends either BaseAdapter or arrayAdapter and provide XML for every Row. – Murtaza Khursheed Hussain Jun 09 '15 at 13:41

2 Answers2

1

You should create a custom ListView adapter that fits your needs, and also create an inflater's xml layout and align the text there whatever you want.

More info here:

Community
  • 1
  • 1
azurh
  • 410
  • 4
  • 12
-2

You should set gravity in your item, that you using in your adapter. And there modify your textView like this way:

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"   <= set this
android:layout_height="wrap_content"
android:text="@string/invalid"
android:gravity="center"   <=this your gravity
/>
Android Android
  • 724
  • 1
  • 7
  • 20