赞
踩
Android 如何判断ListView的滚动方向,直接看代码:
- mListView.setOnScrollListener(new OnScrollListener() {
- int scrollState;
-
- @Override
- public void onScrollStateChanged(AbsListView view, int scrollState) {
- this.scrollState = scrollState;
- }
-
- @Override
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- View v = view.getChildAt(0);
- int top = (v == null) ? 0 : v.getTop();
- int scrollDirection = SCROLL_STOP;
- if (firstVisibleItem > mLastTopIndex) {
- scrollDirection = SCROLL_UP;
- } else if (firstVisibleItem < mLastTopIndex) {
- scrollDirection = SCROLL_DOWN;
- } else {
- if(top < mLastTopPixel) {
- scrollDirection = SCROLL_UP;
- } else if(top > mLastTopPixel) {
- scrollDirection = SCROLL_DOWN;
- }
- }
- mLastTopIndex = firstVisibleItem;
- mLastTopPixel = top;
-
- if (scrollDirection == SCROLL_DOWN) {
-
- } else if (scrollDirection == SCROLL_UP) {
-
- }
- }
- });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。