`
xubingok
  • 浏览: 130725 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

自定义view中获取字符串的宽度和高度

 
阅读更多
方法1:
Rect rect = new Rect();
Paint p = new Paint();
String str = "abcdefg";
p.getTextBounds(str, 0, str.length(), rect);//用一个矩形去"套"字符串,获得能完全套住字符串的最小矩形
float width = rect.width();//字符串的宽度
float height = rect.height();//字符串的高度


方法2:
Paint p = new Paint();
String str = "abcdefg";
float width = p.measureText(str);//获得字符串的宽度
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics