As the question is clearly stated, I want to add a small line spacing after every \n
defined in a string in a resource file in Android.
Let's say we have a string defined in xml like this:
<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>
The normal output when setting it to a TextView
will be like the left side of this image. What I want to achieve is the right side of this image.
There are some attributes in xml like:
android:lineSpacingMultiplier="2"
and
android:lineSpacingExtra="10dp"
but these attributes will only lead to something like this:
So I don't want to add line spacing after every new line because the width of the line is consumed, but only after every defined \n
.
Any way to achieve what I want through code or html? By saying html, I mean something like this, but with some modified stuff after adding <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."));
It is more like I want to create many paragraphs in the TextView
with small line spacing after each paragraph all in one string. I thought that this would be possible to be done through HTML, so that's why I added html tag.
Edit:
I also don't want to add two line breaks because I only want a small line spacing, and putting two line breaks together will have a large line spacing, which I don't want due to some design issues in my app.