【发布时间】:2020-10-16 16:02:00
【问题描述】:
我需要将两个TextViews 与动态内容对齐,因此需要宽度。 ConstraintLayout 工作良好,直到文本开始换行成多行。左视图在第二个视图的宽度上向左移动(超出左边界)。如何避免这种情况?是某种错误还是我忘记了错误地使用ConstraintLayout?
<?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"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="textView2 Lorem ipsum "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="textView1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
app:layout_constraintEnd_toStartOf="@+id/textView2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="@+id/textView2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap" />
</android.support.constraint.ConstraintLayout>
移动视图图像:
【问题讨论】:
-
我也无法控制自动换行的 TextView 的宽度。我正在处理翻译字符串。我很幸运,我可以缩短翻译以防止自动换行。如果这不起作用,我会尝试的下一个方法是分配固定宽度或调查是否可以分配最大宽度。
标签: android xml android-constraintlayout