Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 571
change Avatar asked Oct 08 '13 18:10

change


People also ask

What is lineSpacingExtra?

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. Follow this answer to receive notifications.

What is text view?

A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.


2 Answers

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

like image 88
Jans Avatar answered Sep 22 '22 10:09

Jans


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

like image 27
J David Smith Avatar answered Sep 20 '22 10:09

J David Smith