Skip to content

Instantly share code, notes, and snippets.

@brucetoo
Created December 22, 2015 01:52
Show Gist options
  • Save brucetoo/bd95e86db9e921684225 to your computer and use it in GitHub Desktop.
Save brucetoo/bd95e86db9e921684225 to your computer and use it in GitHub Desktop.
listview 监听顶部滚动的距离的方法
private Dictionary<Integer, Integer> listViewItemHeights = new Hashtable<Integer, Integer>();
private int getListViewScrollY(AbsListView view) {
View c = view.getChildAt(0);
int scrollY = -c.getTop();
listViewItemHeights.put(view.getFirstVisiblePosition(), c.getHeight());
for (int i = 0; i < view.getFirstVisiblePosition(); ++i) {
if (listViewItemHeights.get(i) != null)
scrollY += listViewItemHeights.get(i); //顶部消失的所有Item的高度
}
return scrollY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment