Skip to content

Instantly share code, notes, and snippets.

@goodev
Created November 27, 2013 05:53
Show Gist options
  • Save goodev/7671253 to your computer and use it in GitHub Desktop.
Save goodev/7671253 to your computer and use it in GitHub Desktop.
获取 ListView 的滚动位置
public int getScrollY() {
View c = mListView.getChildAt(0);
if (c == null) {
return 0;
}
int firstVisiblePosition = mListView.getFirstVisiblePosition();
int top = c.getTop();
int headerHeight = 0;
if (firstVisiblePosition >= 1) {
headerHeight = mPlaceHolderView.getHeight();
}
return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment