Reputation: 606
How to get the maximum number of lines that can be written in TextView? I tried this:
DisplayMetrics metrics = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (metrics);
float width = metrics.widthPixels;
float height = metrics.heightPixels;
int lines = (int) (height / textView.getLineHeight ());
System.out.println (lines);
However, this variant gives the wrong information.
Upvotes: 8
Views: 4641
Reputation: 1
textView.getHeight() / textView.getLineHeight()
textView.getHeight()
and textView.getLineHeight()
both will consider the height on the screen with the screen dpi.
Here is the post to get the correct height of view. View's getWidth() and getHeight() returns 0
Upvotes: 0
Reputation: 12900
textview.getLineCount()
It's all in the documentation
EDIT: I was a bit too fast. I assume you want the number of lines that CAN be inside a textview instead of how many there currently ARE in the textview... In that case -> have a look at this question: Calculate text size according to width of text area
Upvotes: 4