1

当我尝试在 TextView 中显示带有文件扩展名的文本时,它会错误地换行。文本每次都在第一个文件扩展名之前的最后一个单词上换行,并以点开头。

代码示例:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="@dimen/margin_regular">

    <TextView
        android:id="@+id/attachFileConditions"
        android:layout_width="300dp"
        android:background="#cccccc"
        android:layout_height="wrap_content"
        android:text="Some file extensions: .docx, .jpg, .pdf, .png, .xls, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx, .xlsx" />
</LinearLayout>

结果是这样的:
结果

预期结果
预期结果

4

2 回答 2

1

为什么 Android TextView 在单词开头错误地用点包装文本(如文件扩展名)?

因为你TextView有静态宽度300dp

你需要改变/增加你的宽度TextView

用这个

android:layout_width="match_parent" 

或者

android:layout_width="wrap_content"

代替

android:layout_width="300dp"
于 2019-04-11T10:26:24.880 回答
0

尝试改变app:breakStrategy="simple"或最适合您的。休息策略参考

在此处输入图像描述

于 2019-04-11T10:29:45.077 回答