Alexander Gorelik
Alexander Gorelik

Reputation: 4385

Android TextView default line spacing

There is a methods that multiply spacing between lines in TextView

I want to multiply it by 2 , but what is the default spacing value that it multiplies? 2px, 5px?

Thanks.

Upvotes: 8

Views: 8941

Answers (2)

kyay10
kyay10

Reputation: 942

After some messing around with Spans, I finally found how to find the default line spacing (the space from the lowest glyph (y) in a line to the tallest glyph (L) in the next line). Here is the code:

public static int getLineSpacing(TextView textContainer){
    Paint.FontMetricsInt fontMetrics = textContainer.getPaint().getFontMetricsInt();
    return fontMetrics.ascent - fontMetrics.top;
}

Upvotes: 2

The value is a 17.1 percent of the text size.

But use 20 percent to be sure that letter like j or g appear correctly

Upvotes: 9

Related Questions