码迷,mamicode.com
首页 > 其他好文 > 详细

LISTVIEW 获取精确的垂直滚动距离

时间:2015-07-08 14:39:10      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

listview.setOnScrollListener(new AbsListView.OnScrollListener() {
private SparseArray<ItemRecod> recordSp = new SparseArray<ItemRecod>(0);
private int mCurrentfirstVisibleItem = 0;


@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {


}


@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mCurrentfirstVisibleItem = firstVisibleItem;
View firstView = view.getChildAt(0);
if (null != firstView) {
ItemRecod itemRecord = recordSp.get(firstVisibleItem);
if (null == itemRecord) {
itemRecord = new ItemRecod();
}
itemRecord.height = firstView.getHeight();
itemRecord.top = firstView.getTop();
recordSp.append(firstVisibleItem, itemRecord);
}
LogUtils.d("xiaoqiang", getScrollY() + "");
}


private int getScrollY() {
int height = 0;
for (int i = 0; i < mCurrentfirstVisibleItem; i++) {
ItemRecod itemRecod = recordSp.get(i);
height += itemRecod.height;
}
ItemRecod itemRecod = recordSp.get(mCurrentfirstVisibleItem);
if (null == itemRecod) {
itemRecod = new ItemRecod();
}
return height - itemRecod.top;
}


class ItemRecod {
int height = 0;
int top = 0;
}
});

版权声明:本文为博主原创文章,未经博主允许不得转载。

LISTVIEW 获取精确的垂直滚动距离

标签:

原文地址:http://blog.csdn.net/nie312122330/article/details/46802311

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!