有時候需要在 程序中計算TextView文本的寬高來動態設置一些數值,在Android中可以使用Paint開計算
TextView tv = new TextView(context);
tv.setTextSize(30);
String str = "計算";
Rect mr = new Rect();
tv.getPaint().getTextBounds(str, 0,str.length(),mr);
獲取到Rect之后就能獲取想要的數值了
有時候需要在 程序中計算TextView文本的寬高來動態設置一些數值,在Android中可以使用Paint開計算
TextView tv = new TextView(context);
tv.setTextSize(30);
String str = "計算";
Rect mr = new Rect();
tv.getPaint().getTextBounds(str, 0,str.length(),mr);
獲取到Rect之后就能獲取想要的數值了