Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do guidelines in ConstraintLayout support RTL

Do Guidelines in ConstraintLayout support RTL? I'm creating a View that has a profile picture and user info to its right. I want the picture to take 30% of the width while the username and details take 70%. Is this a valid use case for Guidelines? I am aware of other implementations but I was wondering whether or not guidelines can be used here. The problem I'm facing is that the guideline remains in it's position on the left after changing the devices language to a RTL language

screenshot

Here is the xml:

<?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">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:background="@color/colorPrimary"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        tools:text="Full Name"
        app:layout_constraintTop_toTopOf="@+id/imageView"
        app:layout_constraintStart_toEndOf="@+id/guideline2" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        tools:text="Android Developer"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toEndOf="@+id/guideline2" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline2"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.30" />


</android.support.constraint.ConstraintLayout>
like image 461
Ibrahim Avatar asked Jul 19 '17 13:07

Ibrahim


People also ask

Can we use relative layout in ConstraintLayout?

It's not the right way. ConstraintLayout came to prevent the usage of nested layouts. Remove the relative layout and put a view on top(zindex) of your clickable zone.

What is ConstraintLayout guideline?

A Guideline can be either horizontal or vertical: Vertical Guidelines have a width of zero and the height of their ConstraintLayout parent. Horizontal Guidelines have a height of zero and the width of their ConstraintLayout parent.

What is the barrier and guideline in the constraint layout?

A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.

What layout is ConstraintLayout most similar to?

ConstraintLayout is similar to that of other View Groups which we have seen in Android such as RelativeLayout, LinearLayout, and many more.


1 Answers

** UPDATE ** The bug on this issue is now marked as fixed by Google. ** END UPDATE **

It seems like the Android team missed this issue.

Percent is calculated from the left only.

So to support RTL you can declare a constant in values/dimens.xml, for example:

<resources>
     <item name="my_percent" format="float" type="dimen">0.3</item>
</resources>

And override this value with its 100-mypercent in values-ldrtl/dimens.xml file.

<resources>
     <item name="my_percent" format="float" type="dimen">0.7</item>
</resources>

Use it:

<android.support.constraint.Guideline
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/guideline2"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="@dimen/my_percent" />
  • If you prefer to re-write a complete layout version for RTL, you can skip declaring dimensions, and use layout-ldrtl/ directory for the RTL version.
like image 172
Amir Uval Avatar answered Sep 18 '22 13:09

Amir Uval