I have a TextView which displays a long text. I want to give some space between lines like in CSS with line-height property. How can I do it?
11 Answers
You can use lineSpacingExtra
and lineSpacingMultiplier
in your XML file.

- 11,101
- 1
- 30
- 43

- 97,993
- 18
- 219
- 200
-
18lineSpacingMultiplier works for me with float values like: android:lineSpacingMultiplier="0.8" – Juan Saravia Mar 25 '15 at 16:58
-
9Can you explain how these work? Where are these measurements taken from? Can you give examples with relation to the font and also language? For example, line spacing is measured from the baseline, but East Asian language have no baseline. Where is the default line spacing defined? Is it in the font itself? – Christopher Perry Aug 01 '16 at 18:52
-
4For example: android:lineSpacingExtra="2dp" – nibbana Apr 16 '20 at 13:59
-
1When I set text background, the background also covers the paddings. – user1034912 May 15 '21 at 03:55
If you want padding between text, try LineSpacingExtra="10sp"
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:lineSpacingExtra="10sp"/>

- 4,136
- 5
- 22
- 41

- 1,076
- 1
- 7
- 4
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)

- 5,348
- 5
- 40
- 70
This supplemental answer shows the effect of changing the line spacing.
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
.

- 484,302
- 314
- 1,365
- 1,393
Adding android:lineSpacingMultiplier="0.8"
can make the line spacing to 80%.

- 5,518
- 9
- 31
- 50

- 338
- 3
- 7
You can either use lineSpacingExtra
or 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="0.8" />
In other words, each line height will be height * multiplier + extra
.

- 1,613
- 1
- 18
- 39
You can use 2 attrs
1. lineSpacingExtra: it use for dp spacing
android:lineSpacingExtra="4dp"
2. lineSpacingMultiplie: it use for relative scale
android:lineSpacingMultiplier="0.8"

- 11,234
- 1
- 68
- 78
As an extended answer to above solutions
Remember you can add <item name="android:lineHeight">16sp</item>
for directly setting the line heights but as per the docs above line works like this -
Explicit height between lines of text. If set, this will override the values set for lineSpacingExtra and lineSpacingMultiplier.
<attr name="lineHeight" format="dimension" />
So be sure to use either lineSpacingExtra & lineSpacingMultiplier
or lineHeight
and not both.

- 3
- 4
It's working for me
just add two lines to your Textview
android:includeFontPadding="false" android:lineSpacingMultiplier="0.8"
<TextView
android:id="@+id/searchByItemTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:fontFamily="@font/dm_sans"
android:includeFontPadding="false"
android:lineSpacingMultiplier="0.8"
android:paddingVertical="3dp"
android:paddingStart="4dp"
android:paddingEnd="6dp"
android:text="@string/date_of_birth"
android:textColor="@color/text_black"
android:textSize="16dp" />
note: don't use android:textAppearance=""

- 228
- 4
- 10