Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text/Layout Alignment in Android (textAlignment, gravity)

What's the difference between android:textAlignment and android:gravity?

like image 915
Chrizzor Avatar asked Apr 24 '13 15:04

Chrizzor


People also ask

What is layout gravity android?

So in general android:layout_gravity attribute is used by child views to tell their parent how they want to be placed inside it, while android:gravity is used by the parent layout to tell the child views how they should be placed inside it.

How do you align text in layout?

android:gravity="center" for text center in TextView. android:gravity="center_horizontal" inner text if you want horizontally centered. android:gravity="center_vertical" inner text if you want vertically centered. android:layout_centerInParent="true" if you want TextView in center position of parent view.

What is text gravity?

gravity is the way the text will align itself in the TextView . The TextView being in wrap_content this does nothing, as the TextView is exactly the size of the text. layout_gravity is the way the TextView will align itself in its parent, in your case in the vertical LinearLayout.

How do I align text in text view?

To align text in TextView at the center vertically and horizontally we need to make use of gravity attribute. Example 1 : You can use center_vertical | center_horizontal value to set the text at the center of the TextView area.


1 Answers

All I can see is that the textAlignment is a member of the View Class and the gravity is the member of TextView class. So for the TextView and its subclasses you can use the gravity while you can use the textAlignment for all Views.

As the TextView and its subclasses need some more text-aligning features, so you can see there are more options in gravity where in textAlignment there are only basic options. Although it is only my guess because I have not found any clear documentation about the difference.

You can see these two links of documentation: textAlignment and gravity.

like image 153
stinepike Avatar answered Sep 22 '22 21:09

stinepike