Android getting exact scroll position in ListView

saarraz1 picture saarraz1 · May 30, 2012 · Viewed 75.9k times · Source

I'd like to get the exact, pixel position of the ListView scroll. And no, I am not referring to the first visible position.

Is there a way to achieve this?

Answer

saarraz1 picture saarraz1 · May 30, 2012

Okay, I found a workaround, using the following code:

View c = listview.getChildAt(0);
int scrolly = -c.getTop() + listview.getFirstVisiblePosition() * c.getHeight();

The way it works is it takes the actual offset of the first visible list item and calculates how far it is from the top of the view to determine how much we are "scrolled into" the view, so now that we know that we can calculate the rest using the regular getFirstVisiblePosition method.