實現(xiàn)該功能需要用到listview的setOnScrollListener這個監(jiān)聽器盈魁。
private boolean scrollFlag = false;// 標記是否滑動
private int lastVisibleItemPosition;// 標記上次滑動位置
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
scrollFlag = true;
} else {
scrollFlag = false;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d("dc", "firstVisibleItem::" + firstVisibleItem +
":visibleItemCount:" + visibleItemCount + ":totalItemCount:" +
totalItemCount);
if (scrollFlag) {
if (firstVisibleItem > lastVisibleItemPosition) {
Log.d("dc", "上滑");
}
if (firstVisibleItem < lastVisibleItemPosition) {
Log.d("dc", "下滑");
}
if (firstVisibleItem == lastVisibleItemPosition) {
return;
}
lastVisibleItemPosition = firstVisibleItem;
}
}