Android: support for binding RTL restrictions

What is the best practice of RTL support in constraint layout in android Studio,
or should I create Separated layouts, one for English and one for Arabic?

English version

English version

The expected layout with the Arabic language The expected layout with the Arabic language

The output layout when changing the device language from English to Arabic Output layout when changing the language from English to Arabic

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="@string/CourseName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView7" android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="16dp" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginLeft="16dp" android:textAppearance="@style/TextAppearance.AppCompat.Display1" /> <Button android:text="@string/enroll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginEnd="16dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginRight="16dp" android:textAppearance="@style/TextAppearance.AppCompat.Display2" /> </android.support.constraint.ConstraintLayout> 
+6
source share
4 answers

As already noted in CommonsWare, you rarely or never use Left / Right if you plan to support RTL, especially if you are targeting the 16+ API.

Replace app:layout_constraintRight_toRightOf="parent" with app:layout_constraintEnd_toEndOf="parent" , etc.

End for Right, Start for Left.

+6
source

Unfortunately, they are not doing it right (or, "The End" ;-)).

In many constraints, such as parent element constraints, Android Studio creates constraints using "Left" / "Right", where it should use "Start" / "End" accordingly. This causes a problem in RTL languages โ€‹โ€‹(each language in which its alphabet is Middle Eastern).

Worse: I have not even seen any open error about this.

My solution: close Android Studio (so it does not jump and does not try to correct the situation during editing), then using Atom and RegExp (or the sed command) I carefully replace " layout_constraintLeft_toLeftOf ", with " layout_constraintStart_toStartOf " and " layout_constraintRight_toRightOf " with " layout_constraintEnd_toEndOf "

Sorry, did not find anything stupid: - (

Note With a chain, this is even worse. The RTL layout does not even cling, nor does it support the layout.

My conclusion in this case was to go back to the old layouts until Google gives mature support for the RTL languages โ€‹โ€‹... after all, RTL was here long before LTR; -)

Update: The solution is next to

I opened a bug for Google. They say that it will be "fixed in 2.4".

Update:

Marked as fixed
Fixed in 2.4

April 25, 2017

+4
source

enter image description here Design mode does not yet support RTL recommendations.

Simple solution - Clean the project so that you do not have a generated file. Replace all "Left" with "Start" all "Right" with "End" in xml files. Note - case sensitive

Here it is!

+1
source

Yes, layout constraints support RTL, but to use RTL constraints, start and end should be used instead of left and right constraints.

Example: use Application: layout_constraintEnd_toEndOf = "parent" instead Application: layout_constraintRight_toRightOf = "parent"

  AND Use 

Application: layout_constraintStart_toStartOf = "parent" instead Application: layout_constraintLeft_toLeftOf = "parent"

0
source

Source: https://habr.com/ru/post/1015069/


All Articles