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>
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.
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.
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.
ConstraintLayout is similar to that of other View Groups which we have seen in Android such as RelativeLayout, LinearLayout, and many more.
** 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" />
layout-ldrtl/
directory for the RTL version.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