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?
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.
The android:gravity attribute is used to arrange the position of the content inside a view (for example text inside a Button widget).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With