0

I been round and round on this, and I can not seem to get the text in the ListView to center. The ListView itself centers good, but text inside is not.. I hate to ask seems so basic..

Here is Code I have:

<ListView
        android:id="@+id/lvVoiceReturn"
        android:layout_width="200dp"
        android:layout_height="48dp"
        android:layout_above="@+id/mute"
        android:layout_toLeftOf="@+id/mute"
        android:gravity="center" >

    </ListView>

Im sure its an easy line of code but i have not located it, urgh.. =/

Thank you. Droidster

Droidster
  • 127
  • 1
  • 2
  • 8

2 Answers2

0

It is because you have used android:gravity="center"

This doesn't center the textview, but centers the text inside of the text view.

What you want to use is

android:layout_centerInParent="true"

If you were using a linear layout, then you could use

android:layout_gravity="center"

This is where you got confused, in a relative layout you can't use this because it will give you a syntax error.

jcw
  • 5,132
  • 7
  • 45
  • 54
  • I tried this but did not move the text in ListView to center of box.. =? – Droidster Nov 11 '12 at 16:17
  • 1
    Look here - http://stackoverflow.com/questions/6295538/set-text-of-listview-in-center-android - or here - http://stackoverflow.com/questions/9483788/center-text-in-a-listview – jcw Nov 11 '12 at 16:20
  • Check those links provided by jcw. There is an answer for your question. – Marcin S. Nov 11 '12 at 16:52
0

If you are using a custom adapter with a custom element layout file then please post the xml here. setting gravity attribute to center for list view does not ensure that your list items are gonna center align.

Abhishek Nandi
  • 4,265
  • 1
  • 30
  • 43