What's the difference between lineSpacingExtra and lineSpacingMultiplier?

AndroidTextviewLine Spacing

Android Problem Overview


I'm adding line spacing in my textview which spans multiple lines. What's the difference between android:lineSpacingExtra and android:lineSpacingMultiplier?

lineSpacingExtra with 2dp worked fine for me but I was wondering what the Multiplier does instead?

Android Solutions


Solution 1 - Android

The difference is that android:lineSpacingExtra add extra spacing between lines of text of TextView and android:lineSpacingMultiplier work as scale factor for height of line space. in other words, each line height will be height*multiplier + extra

Solution 2 - Android

It's rather simple: one is additive and one is multiplicative.

If you have a default line spacing of LINE_SPACING and use:

float x = 2;
float y = 1.5;
setLineSpacing(x, y);

The resulting line spacing will be 1.5*LINE_SPACING + 2

It is important to note that the multiplication happens first! This follows the conventional order of operations (multiplication before addition).

See the docs here: http://developer.android.com/reference/android/widget/TextView.html#setLineSpacing(float, float)

In the future, it might be wise to look up such documentation first. ;)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchangeView Question on Stackoverflow
Solution 1 - AndroidJansView Answer on Stackoverflow
Solution 2 - AndroidJ David SmithView Answer on Stackoverflow