獲取文字寬度:
private int getTextWidth(String text, Paint paint) {
Rect rect = new Rect(); // 文字所在區域的矩形
paint.getTextBounds(text, 0, text.length(), rect);
return rect.width();
}
獲取文字高度:
private int getTextHeight(String text, Paint paint) {
Rect rect = new Rect();
paint.getTextBounds(text, 0, text.length(), rect);
return rect.height();
}