Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:20:08+00:00 2026-06-12T11:20:08+00:00

I want my ListView to look like a notepad, ie with a horizontal lines

  • 0

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):

enter image description here ~~~ enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:20:09+00:00Added an answer on June 12, 2026 at 11:20 am

    The code below is based on the simple example from your question, a custom TextView that draws a line at the bottom(and with no dividers in the list). In this case I would make a custom ListView and override the dispatchDraw method like below:

    class CustomListView extends ListView {
    
        private Paint mPaint = new Paint();
        private Paint mPaintBackground = new Paint();
    
        public CustomListView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mPaint.setColor(Color.RED);
            mPaintBackground.setColor(Color.CYAN);
        }       
    
        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            // ListView's height
            final int currentHeight = getMeasuredHeight();
            // this will let you know the status for the ListView, fitting/not
            // fitting content
            final int scrolledHeight = computeVerticalScrollRange();
            if (scrolledHeight >= currentHeight || scrolledHeight == 0) {
                // there is no need to draw something(for simplicity I assumed that
                // if the adapter has no items i wouldn't draw something on the
                // screen. If you still do want the lines then pick a decent value
                // to simulate a row's height and draw them until you hit the
                // ListView's getMeasuredHeight)
                return;
            } else {
                // get the last drawn child
                final View lastChild = getChildAt(getChildCount() - 1);
                // values used to know where to start drawing lines
                final int lastChildBottom = lastChild.getBottom();
                // last child's height(use this to determine an appropriate value
                // for the row height)
                final int lastChildHeight = lastChild.getMeasuredHeight();
                // determine the number of lines required to fill the ListView
                final int nrOfLines = (currentHeight - lastChildBottom)
                        / lastChildHeight;
                // I used this to simulate a special color for the ListView's row background
                Rect r = new Rect(0, lastChildBottom, getMeasuredWidth(),
                        getMeasuredHeight());           
                canvas.drawRect(r, mPaintBackground);
                for (int i = 0; i < nrOfLines; i++) {
                    canvas.drawLine(0, lastChildBottom + (i + 1) * lastChildHeight,
                            getMeasuredWidth(), lastChildBottom + (i + 1)
                                    * lastChildHeight, mPaint);
                }
            }
        }
    
    }
    

    See if you can use the code above and adapt it to your own needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort ListView items by the content of second column (which can
I want to draw some listview items disabled and would like to mimic the
I want my application to look like this. I am able to get names
For clarification : I want all the custom dialogs to look like system default
I can't get my textbox to update the database. The changes look like they
I want to set an background to my listview that have different size (depending
I have created a custom tab layout which look like this,I want to make
I am displaying a ListView that can have any number of rows. I want
How can I hide the vertical lines between the columns in a WPF ListView
I changed the control template of my ListView to look like this: <Border BorderBrush={TemplateBinding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.