I have some text that have more than one paragraph (using "\n") and want to put a spacing between the paragraphs, but without using "\n\n". But the text from the same paragraph I want to keep them with a lower space.
I tried using lineSpacingExtra
and lineSpacingMultiplier
but it sets spaces to every line (insinde the paragraph too).
I want something like this:
Click anywhere in the paragraph you want to change. Go to Layout, and under Spacing, click the up or down arrows to adjust the distance before or after the paragraph.
Select the text you want to format. On the Home tab, click the Line and Paragraph Spacing command, then select the desired line spacing.
Adding android:lineSpacingMultiplier="0.8" can make the line spacing to 80%. Show activity on this post. You can use TextView. setLineSpacing(n,m) function.
Line spacing determines the amount of vertical space between lines of text in a paragraph. By default, lines are single-spaced, meaning that the spacing accommodates the largest font in that line, plus a small amount of extra space. Paragraph spacing determines the amount of space above or below a paragraph.
You can use Spannable's to achieve this:
String formattedText = text.replaceAll("\n", "\n\n"); SpannableString spannableString = new SpannableString(formattedText); Matcher matcher = Pattern.compile("\n\n").matcher(formattedText); while (matcher.find()) { spannableString.setSpan(new AbsoluteSizeSpan(25, true), matcher.start() + 1, matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
The code above replaces all line breaks with two line breaks. After that it sets absolute size for each second line break.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With