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:

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();
}
Assuming that you know the size of All your items type:
and using your adapter: