Nandha Nandha - 1 year ago 327
Java Question

How to get line count of textview before rendering?

How can I get the number of lines a string will take up in a

before it is rendered.

will not work because those are only fired after it is rendered.

Answer Source
Rect bounds = new Rect();
Paint paint = new Paint();
paint.getTextBounds(testString, 0, testString.length(), bounds);

int width = (int) Math.ceil((float) bounds.width() / currentSize);

Now devide the width of text with the width of your TextView and get the total lines.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download