Paint获取Text的宽和高的数据
获取字符串的宽度:
public static float GetTextWidth(String text, float Size) { // 第一个参数是要计算的字符串,第二个参数是字提大小 TextPaint FontPaint = new TextPaint(); FontPaint.setTextSize(Size); return FontPaint.measureText(text); }
获取字符串长、宽:
public static Rect getTextRect(Paint paint, String str) { Rect rect = new Rect(); paint.getTextBounds(str, 0, str.length() - 1, rect); return rect; }