Android 文本视图可以';t在ConstraintLayout中环绕文本换行
我对ConstraintLayout中的TextView有一个问题,带有约束的xml如下所示:Android 文本视图可以';t在ConstraintLayout中环绕文本换行,android,Android,我对ConstraintLayout中的TextView有一个问题,带有约束的xml如下所示: <TextView ... android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginHorizontal="24dp" android:layout_marginTo
<TextView
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/section_title"
tools:text="Data Processing, Hosting, and Related Services"
/>
整个文本视图都是样式化的,我使用的是flagandroid:breakStrategy=“balanced”
,因此文本视图显示如下:
<TextView
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/section_title"
tools:text="Data Processing, Hosting, and Related Services"
/>
正如您所看到的,它正在扩展其宽度以填充约束,并且没有环绕文本,因此背景无法正确显示。有人知道解决方案吗?删除此标签
app:layout\u constraintEnd\u toEndOf=“parent”
原因-
您已经为textview提供了约束,它将自身与端点对齐
对于父级,因此app:layout\u constraintStart\u toStartOf=“parent”就足够了
将其与父项的开头对齐,并将内容包装为
背景
示例
<TextView
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/section_title"
tools:text="Data Processing, Hosting,\nand Related Services"
/>
当你不使用这个标签android:breakStrategy=“balanced”时会发生什么?它只将“服务”移到下一行,并且在第一行末尾留下一点空白,看起来只是坏掉了包装的固定问题,但是由于没有末端限制,它现在不尊重末端边距。请发布一张现在的图片,这样我就可以看到问题。也请发布一张您所需设计的图片,这样我就可以提供帮助