绘制drawtext无非就是这三种情况

1、 指定矩形尺寸为100*100,在中间位置显示文字(红色字位置)
Rect bounds = new Rect();
paint.getTextBounds(str, 0, str.length(), bounds);
int baseline = 100/2- bounds.bottom + bounds.height() / 2;
搞定!是不是很简单 绝对一点不差在中间位置
2、绿色字在中心线的上方显示
Rect bounds = new Rect();
paint.getTextBounds(str, 0, str.length(), bounds);
int baseline = 100/2- bounds.bottom;
3、浅绿色字在中心线的下方显示
Rect bounds = new Rect();
paint.getTextBounds(str, 0, str.length(), bounds);
int baseline = 100/2+ Math.abs(bounds.top);
网友评论