top,bottom,ascent,descent,baseline
先来看一张图:
文字在绘制的时候,会根据当前的字体,字体大小等信息,确认top,bottom,ascent,descent,baseline的值,这些值会最终影响到字体在TextView中的显示位置,
通过getPaint().getFontMetricsInt()可以获取到这些值
baseline:基准点,字符在TextView中的基准点,字符的绘制就是通过这个基准点来绘制的,相当于字符的零点,top,bottom,ascent,descent的值就是以这个为零点来得到的,在baseline上面的top和ascent是负数,在baseline下面的bottom和descent是正数
top:是指的是最高字符到baseline的值,即ascent的最大值,为负数
ascent:是baseline之上至字符最高处的距离,为负数
bottom:是指最低字符到baseline的值,即descent的最大值,为正数
descent:是baseline之下至字符最低处的距离,为正数
测试
我自定义了一个NonSpaceTextView:
@Override