0
votes

I have a layout with textviews. Whenever I use Left to Right locale OR remove the android:hint elements, it works properly. However, in RTL (Hebrew locale) with LTR value (English text) and gravity="start" or "end" it just pushes the text into a hint sized text view in the wrong direction. Maybe it will be clearer with examples:

LTR locale and text:

enter image description here

RTL locale and LTR text with hints - here the "Data A" field with gravity "end" pushes it to the right instead of left because it is English. "Data B" has gravity "start" so it is the same case, only reversed:

enter image description here

the hints are an important issue because when I remove them, then wrap_content will shrink the view and the layout constraints do their job and it shows up correctly even in RTL

Here is the same example with android:hints removed: enter image description here

LTR layout editor: enter image description here

basically, my question is how to make the gravity of a textview always work towards the end or the start of the locale, and not the language of the text

<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"
    style="@style/LogEntryListViewItemStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"><!--TODO-->

    <ImageView
        android:id="@+id/LogEntryListSelectedFieldField"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/Number"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:gravity="center"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="@+id/LogEntryListSelectedFieldField"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/DataB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:gravity="start"
        app:layout_constraintStart_toEndOf="@+id/Number"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/LogEntryListItemDateTimeField"
        style="@style/LogEntryListItemDateStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:gravity="end"
        app:layout_constraintEnd_toStartOf="@+id/LogEntryListSignedField"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/LogEntryListItemAircraftField"
        style="@style/DataA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        app:layout_constraintStart_toStartOf="@+id/DataB"
        app:layout_constraintTop_toBottomOf="@+id/DataB" />

   <TextView
       android:id="@+id/DataA"
       style="@style/LogEntryListItemAircraftNameStyle"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="end"
       app:layout_constraintEnd_toEndOf="@+id/LogEntryListItemDateTimeField"
       app:layout_constraintTop_toBottomOf="@+id/LogEntryListItemDateTimeField" />

   <android.support.constraint.Barrier
       android:id="@+id/barrier"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       app:barrierDirection="bottom"
       app:constraint_referenced_ids="LogEntryListItemAircraftField, DataA" />

   <TextView
       android:id="@+id/LogEntryListItemNotesField"
       style="@style/LogEntryListItemNotesStyle"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:ellipsize="end"
       android:hint="(Notes)"
       android:maxLines="2"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintStart_toStartOf="@+id/DataB"
       app:layout_constraintEnd_toEndOf="@+id/LogEntryListItemDateTimeField"
       app:layout_constraintTop_toBottomOf="@+id/barrier" />

   <ImageView
       android:id="@+id/LogEntryListSignedField"
       android:layout_width="wrap_content"
       android:layout_height="0dp"
       android:scaleType="center"
       android:src="@drawable/ic_menu_edit"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
1
no it's not the maxLines since it should look like in the first screenshot and use the entire area - PIXP
but the first words on the second line are very short ("xc xfxfx..."). why isn't "xc" in the first line? - PIXP
what is the width of that view which has xc xfxfx text ? - Umair
it's in the xml file - LogEntryListItemNotesField. basically the entire width. - PIXP
ok never mind it was my mistake - it had line feeds... - PIXP

1 Answers

0
votes

I have checked it on my device and it's working alright. Please check and see how it works out.

<?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="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">

<ImageView
    android:id="@+id/LogEntryListSelectedFieldField"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/Number"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:gravity="center"
    android:paddingEnd="10dp"
    android:paddingStart="10dp"
    android:text="20"
    android:textColor="@color/colorPrimaryDark"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="@+id/LogEntryListSelectedFieldField"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/DataB"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:text="Data B"
    android:textColor="@color/colorPrimaryDark"
    app:layout_constraintEnd_toStartOf="@+id/guideline2"
    app:layout_constraintStart_toEndOf="@+id/Number" />

<TextView
    android:id="@+id/LogEntryListItemDateTimeField"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="end|center_vertical"
    android:text="Hercules (C-130)"
    android:textColor="@color/colorPrimaryDark"
    app:layout_constraintEnd_toStartOf="@+id/LogEntryListSignedField"
    app:layout_constraintStart_toStartOf="@+id/guideline2"
    app:layout_constraintTop_toTopOf="parent" />

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

<TextView
    android:id="@+id/LogEntryListItemAircraftField"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="start"
    android:text="Hercules (C-130)"
    android:textColor="@color/colorPrimaryDark"
    app:layout_constraintEnd_toStartOf="@+id/guideline2"
    app:layout_constraintStart_toEndOf="@+id/Number"
    app:layout_constraintTop_toBottomOf="@+id/DataB" />

<TextView
    android:id="@+id/DataA"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:gravity="end|center"
    android:text="Data A"
    android:textColor="@color/colorPrimaryDark"
    app:layout_constraintEnd_toEndOf="@+id/LogEntryListItemDateTimeField"
    app:layout_constraintStart_toStartOf="@+id/LogEntryListItemDateTimeField"
    app:layout_constraintTop_toBottomOf="@+id/LogEntryListItemDateTimeField" />

<android.support.constraint.Barrier
    android:id="@+id/barrier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="bottom"
    app:constraint_referenced_ids="LogEntryListItemAircraftField, DataA" />

<TextView
    android:id="@+id/LogEntryListItemNotesField"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:hint="the hints are an important issue because when I remove them, then wrap_content will shrink the view and the layout constraints do their job and it shows up correctly even in RTL"
    android:maxLines="2"
    android:textSize="12sp"
    android:textStyle="normal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="@+id/LogEntryListItemDateTimeField"
    app:layout_constraintStart_toEndOf="@+id/Number"
    app:layout_constraintTop_toBottomOf="@+id/barrier" />

    <ImageView
    android:id="@+id/LogEntryListSignedField"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:scaleType="center"
    android:src="@drawable/ic_menu_edit"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>