How to increase the spacing between paragraphs in a textview

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.

Leave a Comment