Skip to content

Instantly share code, notes, and snippets.

@foundkey
Created November 5, 2018 04:24
Show Gist options
  • Save foundkey/e189243bcd6e3c9ee3eba335d9dafcf4 to your computer and use it in GitHub Desktop.
Save foundkey/e189243bcd6e3c9ee3eba335d9dafcf4 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment