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 8636531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:15:00+00:00 2026-06-12T10:15:00+00:00

In android, how do i get the scroll position of the listview? I know

  • 0

In android, how do i get the scroll position of the listview?

I know that I can retrieve the scroll position of a uniform populated listview with the following code:

int scrollY = -this.getChildAt(0).getTop() + this.getFirstVisiblePosition()* this.getChildAt(0).getHeight();

the code assumes all heights of children(item) in the listview to be equal(this.getChildAt(0).getHeight())

Now, if i populate my listview with not equally sized items, how do i get the proper scroll position?

My listview looks something like this:
enter image description here

This is why I need the scroll position:

private Canvas drawIndicator(Canvas canvas) {

    int scrollY = getCurrentScrollPosition();



    paint.setColor(Color.GRAY);
    paint.setAlpha(100);
    canvas.drawRect(getLeft(), indicatorPosition[0] - scrollY, getRight(), indicatorPosition[1]
            - scrollY, paint);

     //Log.d(VIEW_LOG_TAG, "drawIndicator:" + (indicatorPosition[1] -
     //scrollY));

    paint.setColor(Color.parseColor("#47B3EA"));
    canvas.drawRect(getLeft(), indicatorPosition[1] - scrollY - (indicatorHeight / 2),
            getRight(), indicatorPosition[1] - scrollY + indicatorHeight, paint);

    return canvas;
}

i need to draw a indicator that follows the scroll of the listview

i would invoke it like

@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    canvas = drawIndicator(canvas);
    super.onDraw(canvas);
    canvas.restore();
}
  • 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-12T10:15:04+00:00Added an answer on June 12, 2026 at 10:15 am

    Assuming that you know the size of All your items type:

    int currentY = 0;
            for (int i = 0; i < listView.getFirstVisiblePosition(); i++) {
    
                int type = listView.getAdapter().getItemViewType(i);
                currentY += getHightForViewType(type);
            }
    
            int scrollY = -listView.getChildAt(0).getTop() + currentY;
    

    and using your adapter:

     private int getHightForViewType(int itemViewType) {
    
            int hightItem;
            switch (itemViewType) {
                case 0:
                    hightItem = 100;
                    break;
    
                default:
                    hightItem = 60;
                    break;
            }
            return hightItem;
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I wanted to get Android source code, I knew that I have to
I have the following code....and I can't seem to get the ads to run
The Android Browser can't scroll inner divs. That means using SlickGrid with its default
I cannot get some Android devices to wake up using the AlarmManager. Following the
I have a an Android ListView that has small (say, 1-5 frame) stutters as
I have a ListView that is being populated with a custom adapter. I'd like
I'm creating an Android app that displays tv-shows on a listview. My shows coming
I have custom listview. When I scroll my listview, android keeps in memory (as
I followed this link Android get external IP . I am connecting to this
I am trying to get Android USB host mode to work; but I need

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.