Rect bounds = new Rect();
String text = "测试";
TextPaint paint;
paint = findViewById(R.id.hello_world).getPaint();
paint.getTextBounds(text, 0, text.length(), bounds);
int height = getStringHeight = (text, paint)
private int getStringHeight(String string, Paint paint) {
Rect rect = new Rect();
paint.getTextBounds(string, 0, string.length(), rect);
return rect.height();
}
private int getStringWidth(String string, Paint paint) {
Rect rect = new Rect();
paint.getTextBounds(string, 0, string.length(), rect);
return rect.width();
}