change
change

Reputation: 672

What's the difference between lineSpacingExtra and lineSpacingMultiplier?

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?

Upvotes: 52

Views: 35756

Answers (2)

Jans
Jans

Reputation: 11250

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

Upvotes: 63

J David Smith
J David Smith

Reputation: 4810

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

Upvotes: 16

Related Questions