Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView padding between lines

People also ask

How to reduce space between lineS in android TextView?

Just we need to add an attribute with your TextView that give the spacing with lines. These are –android:lineSpacingExtra, android:lineSpacingMultiplier – use these two attributes with your TextView in XML file. or Programatically call setter method of that attribute textView. setLineSpacing().

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 height in TextView?

Line height usually means text size + "padding" top/bottom. So, if your designer write line height 19sp and text size 15sp, it means you need to have extra padding 4sp. 19sp - 15sp = 4sp. To implement it in your layout, use lineSpacingExtra attribute.

What is default line spacing in android?

android:lineSpacingMultiplier governs the spacing between lines with a default of "1".


You can use lineSpacingExtra and lineSpacingMultiplier in your XML file.


If you want padding between text try LineSpacingExtra="10dp"

<TextView
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:lineSpacingExtra="10dp"/>

you can look into android:lineSpacingExtra and apply it to your XML

Additional Info is on this page

or the related method public void setLineSpacing (float add, float mult)

Additional Info here


This supplemental answer shows the effect of changing the line spacing.

enter image description here

You can set the multiplier and/or extra spacing with

textView.setLineSpacing(float add, float mult)

Or you can get the values with

int lineHeight = textView.getLineHeight();
float add = tvSampleText.getLineSpacingExtra();          // API 16+
float mult = tvSampleText.getLineSpacingMultiplier();    // API 16+

where the formula is

lineHeight = fontMetricsLineHeight * mult + add

The default multiplier is 1 and the default extra spacing is 0.


You can use TextView.setLineSpacing(n,m) function.


Adding android:lineSpacingMultiplier="0.8" can make the line spacing to 80%.


You can use lineSpacingExtra and lineSpacingMultiplier in your XML file.

lineSpacingExtra add extra spacing between lines of text of TextView

<TextView
    android:lineSpacingExtra="4dp" />

lineSpacingMultiplier works as scale factor for height of line space:

<TextView
    android:lineSpacingMultiplier="1.2" />

In other words, each line height will be height * multiplier + extra.