Skip to content

Instantly share code, notes, and snippets.

@foundkey
foundkey / textBound.java
Created November 5, 2018 04:24
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);