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
Shell Script in Android Gives [: Not Found
System Is Returning Error 127 When Called from C++ in Linux
Android 2.1 Programmatically Unmount Sdcard
Schedule a Work on a Specific Time with Workmanager
How to Make a Gridlayout Fit Screen Size
Webview's HTML Button Click Detection in Activity
Get Text from Web Page to String
How to Make a Phone Call from HTML on Android
Tools: Replace Not Replacing in Android Manifest
How to Take a Screenshot of a Current Activity and Then Share It
How to Create a Table with Borders in Android
Convert a Bitmap to Grayscale in Android
How to Make a Scroll Listener for Webview in Android
How to View Androidmanifest.Xml from APK File
What Are My Options for Storing Data When Using React Native? (iOS and Android)