Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android : is constraint layout support RTL

what is the best practice to support RTL in constraint layout in android Studio,
or should I create A separated layouts one for English and the other for Arabic?

English Version

English version

The Expected layout with Arabic language The Expected layout with Arabic language

The output layout when I change the Device Language from English to Arabic The output layout when Change 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>
like image 442
manar musTapha Avatar asked Feb 17 '17 16:02

manar musTapha


People also ask

What is support RTL in Android?

Android 4.1 (Jelly Bean) introduced limited support for bidirectional text in TextView and EditText elements, allowing apps to display and edit text in both left-to-right (LTR) and right-to-left (RTL) scripts.

How do I use RTL support on Android?

Just go to Android Studio > Refactor > Add RTL support where possible… I would recommend you checking your app once after applying this change as you might not want all your Layouts/Views to be RTL. If you want to force any layout to LTR then just add android:layoutDirection="ltr" to that view.

What is RTL support?

Some languages of the world (Arabic, Hebrew etc.) are RTL, meaning they are read right-to-left, instead of left-to-right. Typically in web applications supporting one of these languages, everything is reversed, meaning scroll bars, progress indicators, buttons etc.

What is constraint horizontal bias Android?

Bias, in terms of ConstraintLayout , means "if there is extra room, slide the widget in this direction along the axis". The default bias is 0.5, meaning that the widget is centered in the available space.


1 Answers

As Already pointed out by CommonsWare, you should rarely/never use Left/Right if you plan on supporting RTL languages, especially if you target API 16+.

Replace your app:layout_constraintRight_toRightOf="parent" with app:layout_constraintEnd_toEndOf="parent" and so forth.

End for Right, Start for Left.

like image 104
Martin Marconcini Avatar answered Oct 04 '22 18:10

Martin Marconcini