首页 > 技术文章 > android canvas drawtext 字高

mamamia 2018-11-09 14:50 原文

Paint pFont = new Paint();
Rect rect = new Rect();
pFont.getTextBounds("豆", 0, 1, rect);
Log.v(TAG, "height:"+rect.height()+"width:"+rect.width());

得到字高。

或者
float textHeight = mPait.getFontMetrics().descent - mPaint.getFontMetrics().ascent;

drawtext以baseline为基准去画的。注意位置。

推荐阅读