如何在文本视图中自动换行,这样它就不会偶尔分解单词



我在下面有这段代码来处理我的问题的文本视图:

<TextView
android:id="@+id/textquestion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:gravity="center"
android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
android:scrollHorizontally="false"/>

然而,我注意到了一些事情。有时,如果单词到达末尾并且不适合,而不是将单词向下移动到下一行,它会像这样用 - 将单词分解。

This is an example test to show that th-
is text breaks as you can see and not
move the word down to the next line.

我需要在上面的 xml 中包含什么才能对其进行自动换行?

尝试使用

android:breakStrategy="simple"

您可以通过在xml中使用breakStrategy或动态设置属性来执行此操作

共有三种类型的breakStrategy可用
1(简单,
2(high_quality,3
(平衡

您可以使用上面的任何一种,这为您提供不同的换行策略,

android:breakStrategy="high_quality"

另外,在谷歌上找到一张用图形解释你的图片 https://t1.daumcdn.net/cfile/tistory/267FFD3E57BADA6121

最新更新