Get the size of a text in TextView

Rect bounds = new Rect();

textView.getPaint().getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bounds);

bounds.width() will give you the accurate width of the text in the Text View.


If your textview is called tv

tv.setText("bla");
tv.measure(0, 0);       //must call measure!
tv.getMeasuredHeight(); //get height
tv.getMeasuredWidth();  //get width

More on this (updated): How to get width/height of a View


For some reason the solution of Midverse Engineer does not give me always correct results (at least on some Android versions). The solution of Sherif elKhatib works, but has the side effect of changing MeasuredWidth and Height. This could lead to incorrect positioning of the textView.

My solution:

width = textView.getPaint().measureText(text);
metrics = textView.getPaint().getFontMetrics();
height = metrics.bottom - metrics.top;