I want my ListView to look like a notepad, ie with a horizontal lines background pattern. Following the Notepad sample, I can extend TextView and override its onDraw() like this:
r = new Rect();
for (int i = 0; i < getLineCount(); i++) {
int baseline = getLineBounds(i, r);
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
}
super.onDraw(canvas);
but when there are just a few elements in the list, there won’t be enough lines to fill the page (actual result on the left, desired on the right):
~~~ 
So I tried an alternative approach: overriding ListView.onDraw(). Unfortunately, there’s no immediate way to compute the top scroll (getScrollY() always returns 0), and above all, I must disable all caching and drawing optimizations, and this will definitely kill performance, other than not being scalable for large lists.
Finally, my row widgets are not plain text views. They are complex layouts, even if the main content is -sure- a TextView. This means that inside the layout I can’t call getLineBounds() (a layout is not a text view), and in the text view I can’t because the TextView is smaller than the surrounding layout, so there will be gaps on the four sides.
How can I architect a solution to display my custom widgets and fill the entire window with horizontal lines? A naive approach would be to add dummy empty elements to the list as long as it fits all the available space, however this is a hack and there must be a better way of doing things. Using a background image is not an option, since the distance between lines must be customizable at runtime.
The code below is based on the simple example from your question, a custom
TextViewthat draws a line at the bottom(and with no dividers in the list). In this case I would make a customListViewand override thedispatchDrawmethod like below:See if you can use the code above and adapt it to your own needs.