Reputation: 103
The TextView(left) shows the number of lines(using the getLineCount method) in the EditText(right). However the getLineCount method returns a value of 2 even though there's only 1 line. Initially it returns 1 but it returns 2 as soon as the viewport is filled with characters and on addition of another character. Please note that the EditText is inside a HorizontalScrollView, so that the text doesn't wrap to the next line. I have added pictures to explain this effectively. https://i.sstatic.net/BNABs.png https://i.sstatic.net/WJ2BW.png
Upvotes: 2
Views: 995
Reputation: 16537
getLineCount()
internally uses StaticLayout or DynamicLayout to measure content and it doesn't reflect EditText one to one. I'm not sure about the measurement details, but apparently you're interested in line count by line endings. If so, you can just count line endings in text and add 1. See: Count the number of lines in a Java String
Upvotes: 1