mListView.setOnScrollListener(new OnScrollListener() {
private SparseArray recordSp = new SparseArray(0);
private int mCurrentfirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
mCurrentfirstVisibleItem = firstVisibleItem;
View firstView = view.getChildAt(0);
if (null != firstView) {
ItemRecod itemRecord = (ItemRecod) recordSp
.get(firstVisibleItem);
if (null == itemRecord) {
itemRecord = new ItemRecod();
}
itemRecord.height = firstView.getHeight();
itemRecord.top = firstView.getTop();
recordSp.append(firstVisibleItem, itemRecord);
}
//Log.v("yzj------",getScrollY()+"recordSp:"+recordSp.toString());
getScrollY();
}
private int getScrollY() {
int height = 0;
for (int i = 0; i < mCurrentfirstVisibleItem; i++) {
ItemRecod itemRecod = (ItemRecod) recordSp.get(i);
height += itemRecod.height;
}
ItemRecod itemRecod = (ItemRecod) recordSp
.get(mCurrentfirstVisibleItem);
if (null == itemRecod) {
itemRecod = new ItemRecod();
}
return height - itemRecod.top;
}
class ItemRecod {
int height = 0;
int top = 0;
}
});
private SparseArray recordSp = new SparseArray(0);
private int mCurrentfirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
mCurrentfirstVisibleItem = firstVisibleItem;
View firstView = view.getChildAt(0);
if (null != firstView) {
ItemRecod itemRecord = (ItemRecod) recordSp
.get(firstVisibleItem);
if (null == itemRecord) {
itemRecord = new ItemRecod();
}
itemRecord.height = firstView.getHeight();
itemRecord.top = firstView.getTop();
recordSp.append(firstVisibleItem, itemRecord);
}
//Log.v("yzj------",getScrollY()+"recordSp:"+recordSp.toString());
getScrollY();
}
private int getScrollY() {
int height = 0;
for (int i = 0; i < mCurrentfirstVisibleItem; i++) {
ItemRecod itemRecod = (ItemRecod) recordSp.get(i);
height += itemRecod.height;
}
ItemRecod itemRecod = (ItemRecod) recordSp
.get(mCurrentfirstVisibleItem);
if (null == itemRecod) {
itemRecod = new ItemRecod();
}
return height - itemRecod.top;
}
class ItemRecod {
int height = 0;
int top = 0;
}
});