如图所示这五个变量定义文字的五个部分。下面是FontMetrics源代码
/** * Class that describes the various metrics for a font at a given text size. * Remember, Y values increase going down, so those values will be positive, * and values that measure distances going up will be negative. This class * is returned by getFontMetrics(). */ public static class FontMetrics { /** * The maximum distance above the baseline for the tallest glyph in * the font at a given text size. */ public float top; /** * The recommended distance above the baseline for singled spaced text. */ public float ascent; /** * The recommended distance below the baseline for singled spaced text. */ public float descent; /** * The maximum distance below the baseline for the lowest glyph in * the font at a given text size. */ public float bottom; /** * The recommended additional space to add between lines of text. */ public float leading; }
在Android中,Baseline是基线,绘制文字都是以Baseline为准,ascent是上坡度,指的是Baseline往上至字符“最高处”的距离;descent是下坡度指的是Baseline往下至字符“最低处”的距离。
上一行字符的descent到下一行行字符的ascent之间的距离为leading(行间距)
由于有些文字还带有字符如图中顶端波浪形的符号,Baseline到字符顶端的距离就是top,Baseline到字符底端包含行间距距离就是bottom
top的意思其实就是除了Baseline到字符顶端的距离外还应该包含这些符号的高度,bottom的意思也是一样。一般情况下我们极少使用到类似的符号所以往往会忽略掉这些符号的存在