我有一个带有textviews的布局。 每当我使用从左到右的语言环境 OR 删除android:提示元素时,它都能正常工作。但是,在具有LTR值(英文文本)和gravity =“start”或“end”的RTL(希伯来语语言环境)中,它只是将文本推入错误方向的提示大小的文本视图中。也许用例子会更清楚:
LTR区域设置和文字:
带有提示的RTL语言环境和LTR文本 - 这里“重力为”结尾的“数据A”字段将其推向右侧而不是左侧,因为它是英语。 “数据B”具有引力“开始”所以它是相同的情况,只是逆转:
提示是一个重要的问题,因为当我删除它们时,wrap_content会缩小视图,布局约束会完成它们的工作,即使在RTL中它也能正确显示
基本上,我的问题是如何使textview的重力始终朝向语言环境的结束或开始,而不是文本的语言
<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>
答案 0 :(得分:0)
我已经在我的设备上检查了它并且它正常工作。请检查并查看它是如何工作的。
<?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>