Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is TextView Gravity by default?

It seems TextView text direction (or Gravity) automatically changes in Android when it gets text from RTL resources such as Arabic text or LTR resources like English. What is the default TextView direction (or Gravity) and how to get that? Actually I'm trying to find out what kind of text language (RTL or LTR) is entered? And what if it is hybrid text with both RTL and LTR?

like image 857
Mariox Avatar asked Nov 08 '15 12:11

Mariox


People also ask

What is gravity in android layout?

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.

What is gravity start android?

The android:gravity attribute is used to arrange the position of the content inside a view (for example text inside a Button widget).

What does gravity command used for?

The android:gravity specifies how an object should position its content on both X and Y axis. The possible values of android:gravity are top, bottom, left, right, center, center_vertical, center_horizontal etc. The android:gravity is used to control gravity of all child views of a container.

What is the TextView?

TextView is the user interface which displays the text message on the screen to the user. It is based on the layout size, style, and color, etc. TextView is used to set and display the text according to our specifications.


1 Answers

What is the default TextView direction (or Gravity)

In the TextView source code it is initialized as:

private int mGravity = Gravity.TOP | Gravity.START;

It seems Gravity.TOP and Gravity.START. The Gravity START is independent for LTR or RTL.

and how to get that

So getting it (you only know it Gravity.START) is non-sense for your purpose -- to find out what kind of text language (RTL or LTR) is entered.

For other approach you can estimate whether text itself is RTL or LTR; discussed here: Identifyng RTL language in Android for example.

like image 181
hata Avatar answered Oct 13 '22 03:10

hata