Mikuz Mikuz - 1 year ago 126
Android Question

How to get string width on Android?

I would like to get height too if possible.

Answer Source

You can use the getTextBounds(String text, int start, int end, Rect bounds) method of a Paint object. You can either use the paint object supplied by a TextView or build one yourself with your desired text appearance.

Using a Textview you Can do the following:

Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int height = bounds.height();
int width = bounds.width();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download