foundkey
11/5/2018 - 4:23 AM

textRect

Calc Text bound

String str = "Hello World";
Paint calcTextRect = new Paint();
String familyName = “宋体”;
Typeface font = Typeface.create(familyName,Typeface.BOLD);
calcTextRect.setTypeface(font);    // 设置字体
calcTextRect.setColor(Color.RED);  // 设置颜色
calcTextRect.setTextSize(22);      // 设置字体大小
Rect rect = new Rect();
calcTextRect.getTextBounds(str, 0, 1, rect);