android字符测量

通过Paint的getFontMetrics() 方法可以获得一个FontMetrics对象,它有如下的属性:

public float ascent The recommended distance above the baseline for singled spaced text.
public float bottom The maximum distance below the baseline for the lowest glyph in the font at a given text size.
public float descent The recommended distance below the baseline for singled spaced text.
public float leading The recommended additional space to add between lines of text.
public float top The maximum distance above the baseline for the tallest glyph in the font at a given text size.
具体意思可以参考下面这张图的标识:



android开发中经常需要获取文字所占的大小,textview在被显示之前都是获取不到大小的,所以这里需要我们自己计算。

字符的宽度一般用textpaint的measureText(text)方法即可,高度的话需要计算ascent+descent,如果多行的情况还需要加上行间距。textpaint的getTextSize()方法获取的不是字体的高度。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值