Kalina
Kalina

Reputation: 5594

How to find out how many lines text wraps to in a TextView on Android?

I have a long String that wraps to multiple lines, and that number of lines is different depending on the size of the Android device being used. Is there a way to know how many lines the text wraps to?

Upvotes: 3

Views: 2146

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

You can use one of the Layout classes:

Layout layout = new StaticLayout(text, /* other stuff--see docs */);
int nLines = layout.getLineCount();

Upvotes: 3

Related Questions