如何获得一个TextView的linespacing? [英] How to get linespacing of a TextView?
问题描述
有没有什么办法让一个的TextView
的linespacing在的Android
?我试图找到的FontMetrics
的的油漆
的的TextView
而这样做:
Is there any way to get the linespacing of a TextView
in Android
? I try to find fontMetrics
of the Paint
of the TextView
and do like this:
tv1.getPaint().getFontMetrics(pfm);
float fontTop = pfm.top;
float fontBottom = pfm.bottom;
System.out.println("Line Space >> " + (fontBottom - fontTop));
但似乎结果是一样的,直到我修改的TextView
的字体大小。所以,我怎么能得到的linespacing一个的TextView
But it seems that result is the same until I change font size of the TextView
. So how can I get the linespacing of a TextView
?
推荐答案
行间距由它的高度乘以行乘数和一个额外的间距。这会给你一个TextView的路线linespacing:
Line spacing consists of its height multiplied by line multiplier and an extra spacing. This will give you linespacing of a TextView's line:
textView.getPaint().getFontSpacing() * textView.getLineSpacingMultiplier() + textView.getLineSpacingExtra();
但是,请记住,您可以利用getLineSpacingMultiplier()和getLineSpacingExtra的()仅适用于API级别的方法+ 16
However, keep in mind that you can make use of the getLineSpacingMultiplier() and getLineSpacingExtra() methods only for API level 16+.
这篇关于如何获得一个TextView的linespacing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!