Reputation: 52
I am using a text view, and its width is matching the parent. I want to set its text to centre right position. If I use android:gravity="right"
then why does it move to the upper right position?
I am using this:
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:textStyle="bold" />
I have tried this many times, but I could not get good results.
Upvotes: 0
Views: 174
Reputation:
If you want to center the text with respect to the layout, use android:layout_gravity="center"
, but if you just want the letter to center with respect to the whole word, use android:gravity="center"
.
Upvotes: 0
Reputation: 678
You can use:
android:gravity="canter"
And then use
android:paddingLeft="<your value>"
Upvotes: 0
Reputation: 748
Use the android:gravity
property with pipeline|, setting the property to Center as well as Right position.
android:gravity="center|right"
Upvotes: 3
Reputation: 699
You can use android:padding
to match your requirements. Also use android:gravity="center|right"
.
Upvotes: 3
Reputation: 5378
Try this:
android:gravity="right|center_vertical"
want to align horizontal: android:gravity="right|center_horizontal"
Upvotes: 0
Reputation: 6925
Try this
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center_vertical|right" />
Upvotes: 0