Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the spacing between paragraphs in a textview

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:

Multiparagraph padding

like image 486
IIRed-DeathII Avatar asked Oct 13 '15 14:10

IIRed-DeathII


People also ask

What is the best way to adjust the space between paragraphs?

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.

How do you put a space between paragraphs in text?

Select the text you want to format. On the Home tab, click the Line and Paragraph Spacing command, then select the desired line spacing.

How do I increase line spacing in android?

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.

What is line spacing extra?

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.


1 Answers

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.

like image 62
Ermat Alymbaev Avatar answered Oct 09 '22 02:10

Ermat Alymbaev