Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating width of a string on Android

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()

like image 297
exebook Avatar asked Jan 14 '23 23:01

exebook


1 Answers

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();
like image 66
Shailendra Singh Rajawat Avatar answered Jan 21 '23 17:01

Shailendra Singh Rajawat