51

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?

Jonik
  • 80,077
  • 70
  • 264
  • 372
change
  • 662
  • 1
  • 6
  • 11

2 Answers2

61

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

Jans
  • 11,064
  • 3
  • 37
  • 45
16

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. ;)

J David Smith
  • 4,780
  • 1
  • 19
  • 24