Calculating width of a string on Android

2019-05-08 19:18发布

I need to know width of text string given font handle (or font name + font size + font style data).

in Windows I used to use GetTextExtentPoint()

2条回答
做个烂人
2楼-- · 2019-05-08 19:32
家丑人穷心不美
3楼-- · 2019-05-08 19:48

use this code

 Rect bounds = new Rect(); 
 Paint textPaint = textView.getPaint();
 textPaint.getTextBounds(text, 0, text.length(), bounds); 
 int height = bounds.height(); 
 int width = bounds.width();
查看更多
登录 后发表回答