正如问题所明确指出的那样,我想在每个之后添加一个小行距\n
在 Android 资源文件的字符串中定义。
假设我们在 xml 中定义了一个字符串,如下所示:
<string name="line_test">This is the 1st line. This is still the 1st line.\nThis is the 2nd line.\nThis is the 3rd line. This is still the 3rd line.\nThis is the 4th line.</string>
设置为a时正常输出TextView
就像这张图片的左侧一样。我想要实现的是该图像的右侧。
xml中有一些属性,例如:
android:lineSpacingMultiplier="2"
and
android:lineSpacingExtra="10dp"
但这些属性只会导致这样的结果:
所以我不想在每个新行之后添加行距,因为行的宽度被消耗,但仅在每个定义之后添加\n
.
有什么办法可以通过代码或html来实现我想要的吗?我所说的 html 是指类似这样的东西,但是添加后进行了一些修改<br/>
:
textView.setText(Html.fromHtml("This is the 1st line. This is still the 1st line.<br/>This is the 2nd line.<br/>This is the 3rd line. This is still the 3rd line.<br/>This is the 4th line."));
更像是我想在其中创建许多段落TextView
每个段落后的行距都在一个字符串中。我认为这可以通过 HTML 来完成,所以这就是我添加 html 标签的原因。
Edit:
我也不想添加两个换行符,因为我只想要一个小的行距,而将两个换行符放在一起将会有一个大的行距,由于我的应用程序中的一些设计问题,我不希望出现这种情况。