【发布时间】:2016-05-12 17:55:27
【问题描述】:
正如问题已明确指出的那样,我想在 Android 资源文件的字符串中定义的每个 \n 之后添加一个小行距。
假设我们在 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>
将其设置为TextView 时的正常输出将类似于此图像的左侧。我想要实现的是这张图片的右侧。
xml中有一些属性,比如:
android:lineSpacingMultiplier="2"
和
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 标签。
编辑:
我也不想添加两个换行符,因为我只想要一个小的行间距,而将两个换行符放在一起会有很大的行间距,由于我的应用程序中的一些设计问题,我不希望这样做.
【问题讨论】:
-
为什么不给两个换行符? \n\n
标签: android html string newline spacing