在某些语言中,不在行尾添加连字符来连接单词

Hyphens are not added at line endings to join words in some languages

我在 ConstraintLayout 中有以下 TextView

 <TextView
        android:id="@+id/title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="3"
        android:textAppearance="@style/TextAppearance.AppCompat.Title"
        ... />

当文本太长无法放在一行时,会分成两行。但是,如果系统语言设置为瑞典语,它将在单词中间中断而不添加连字符,如下所示:

Some text that is br oken into two lines

我不确定这是否是一个准确的例子,但你明白了。

我要的是这个:

Some text that is br- oken into two lines

当系统语言设置为英语时,它确实有效。但它也应该适用于瑞典语。

我已经在 TextView 上尝试了 android:breakStrategy="..."android:hyphenationFrequency="..." 的所有可能组合。

compileSdkVersion 28
targetSdkVersion 28
minSdkVersion 28

我认为问题出在不同语言的本地化和字符编码上。

我想您正在使用翻译编辑器来支持本地化。尝试获取每个 textView(等...)的字符串并使用以下方法将其转换为 utf-8 格式:

URLEncoder.encode(your string, "utf-8");

然后将textView文本设置为这个字符串:

textView.setText(your string);

如果语言设置为英语,则仅添加连字符以连接换行符中的单词。这可能是一个错误。资料来源:https://issuetracker.google.com/issues/37087785 https://issuetracker.google.com/issues/37010641 https://issuetracker.google.com/issues/79936443