Example for Android textview alignment –

To align a textview we need to use the ‘gravity’ property

<TextView android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center" />

Now we set the alignment to center so that textview text will appear in the center of the textview(see the below image).

textviewaligmentcenter

We can set the gravity as top, right, left, bottom,etc…you can also set more than one gravity at a time.

For instance,

android:gravity=”right|center”

textviewalignmentcenterright

(Note: The red color lines won’t appear in the output.)

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply