有时候需要在 程序中计算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之后就能获取想要的数值了
本文标题:TextView 计算文字宽高
本文链接:https://www.haomeiwen.com/subject/gxvqvttx.html
网友评论