Here we are going to see about how to set textview alignment in Android.
It is very simple to set Android textview alignment to the center, right or left etc..
Example for Android textview alignment -
To align a textview we need to use the 'gravity' property
[sourcecode language="xml"]
<TextView android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center" />
[/sourcecode]
Now we set the alignment to center so that textview text will appear in the center of the textview(see the below image).
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"
Note: (The red color lines won’t appear in the output.)
It is very simple to set Android textview alignment to the center, right or left etc..
Example for Android textview alignment -
To align a textview we need to use the 'gravity' property
[sourcecode language="xml"]
<TextView android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center" />
[/sourcecode]
Now we set the alignment to center so that textview text will appear in the center of the textview(see the below image).
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"
Note: (The red color lines won’t appear in the output.)
No comments:
Post a Comment