我正在为我的应用程序创建一个UI,其中我需要显示如下段落

为此,我使用了Textview,如下所示
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp24"
android:fontFamily="sans-serif-thin"
android:text="@string/sample_description"
android:textColor="@color/black"
android:lineSpacingExtra="@dimen/dp4"
/>但是我的输出是这样的

如果您注意到,在我的输出中,在某些行的末尾有一些空格。我不想要它。
如果你在第一张图中看到,末尾已经没有空格了。他们在单词之间加了空格,去掉了末尾的空格。
那么,我的问题是如何实现第一个图像输出?
发布于 2021-10-03 16:57:49
如果您使用Android 8+,您可以使用以下命令获得理由:
android:justificationMode="inter_word".或者,您可以使用WebView将文本以HTML格式放入:
<string name="sporttext">
<![CDATA[
<html>
<head></head>
<body style="text-align:justify;color:gray;background-color:white;">
This sport shirt is crafted from scratch ...
</body>
</html>
]]>
</string>发布于 2021-10-03 14:53:08
你需要的东西被称为“对齐的内容”。您可以使用以下命令来实现此目的
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:justificationMode="inter_word" />https://stackoverflow.com/questions/69425856
复制相似问题