tags:

views:

736

answers:

3

How can i put textview with id="naslov" to the center? I also tried with layout_gravity="center" but that doesn't work either.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView   
    android:id="@+id/naslov"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20dip"
    android:text="Povzetek"
    android:gravity="center"/>
   <TextView   
    android:id="@+id/aha"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="10dip"
    android:text="Vseh oddaj:"
       android:layout_below="@id/naslov"/>  
 </RelativeLayout> 
A: 

android:layout_gravity="center_horizontal" as an attribute on the TextView in question.

synic
not gonna work with relative
Alex Volovoy
It's strangly not working on 1.5 , 1.6 emulator and on 1.5 phone.
DixieFlatline
Is it impossible to position text in the center using relative layout?
DixieFlatline
+2  A: 
 android:layout_centerHorizontal="true"

there is also

android:layout_centerInParent="true"

Full list for RelativeLayout attributes is here

Also you can tell your TextView to fill_parent and then set gravity=center on it. So it'll center actual text within textView.

Alex Volovoy
Works like charm. Tnx
DixieFlatline
A: 

This is about the same as http://stackoverflow.com/questions/2990882.

If you look at my answer, it has a full example of how to make this layout work.

Charles Merriam