一.自定义View中测量具体字符串的宽度的方法
1.使用Paint中的measureText方法
代码示例:
mPaint.measureText(“具体的字符串”),可以获取的宽度,但是获取不了高度
2.使用 Rect来获取具体字符串的宽度和高度
代码示例:
String mStr = "具体字符串";
Rect mRect = new Rect();
mPaint.getTextBounds(mStr, 0, mStr.length(), mRect);
int mStrWidth = mRect.width();
int mStrHeight = mRect.height();