`有不少同学对Android 中的文本绘制的相关知识不了解,或者每次当自己想绘制文本时,总是画不出自己想要的效果,根本原因就是对FontMetrics不甚了解,今天就来给大家普及下相关的知识,让大家彻底弄明白文本是如何绘制,以及相关的基础知识,首先看一张图:
大家只用看三个地方,ascent,descent,baseline,其实最重要的就是baseline,如果确认了baseline,我们就能确认文本在垂直方向上的位置。
而baseline的计算需要依赖ascent和descent。大家看的时候,是不是不知道ascent,descent,baseline是什么鬼,那我们来看看FontMetrics,这个类,我们可以通过
Paint.getFontMetrics()接口来获取,先看看源码:
/**
* 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