Android Textview Padding Between Lines

Android TextView padding between lines

You can use lineSpacingExtra and lineSpacingMultiplier in your XML file.

How to increase the spacing between lines in a textview.?

from code you can use textView.setLineSpacing() or from xml you can use android:lineSpacingExtra

How to set a line spacing in a text of a TextView

Take a look at android:lineSpacingExtra (https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingExtra) and android:lineSpacingMultiplier (https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingMultiplier).

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingExtra="5dp"
android:text="abc \n defgh"/>

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.

How to set a line spacing in a text of a TextView

Take a look at android:lineSpacingExtra (https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingExtra) and android:lineSpacingMultiplier (https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingMultiplier).

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingExtra="5dp"
android:text="abc \n defgh"/>

How to reduce the spacing between the lines where there is a single long text in a TextView

You go in the right direction, lineSpacingExtra and lineSpacingMultiplier can help you achieve your goal. Note android:lineSpacingExtra="xdp" with x must greater than 1. lineSpacingMultiplier is a float like your usage.
However, you can set it programmatically by TextView.setLineSpacing()



Related Topics



Leave a reply



Submit