当前位置:   article > 正文

Android 如何判断ListView的滚动方向_java listview scrolldirection

java listview scrolldirection

Android 如何判断ListView的滚动方向,直接看代码:

  1. mListView.setOnScrollListener(new OnScrollListener() {
  2. int scrollState;
  3. @Override
  4. public void onScrollStateChanged(AbsListView view, int scrollState) {
  5. this.scrollState = scrollState;
  6. }
  7. @Override
  8. public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
  9. View v = view.getChildAt(0);
  10. int top = (v == null) ? 0 : v.getTop();
  11. int scrollDirection = SCROLL_STOP;
  12. if (firstVisibleItem > mLastTopIndex) {
  13. scrollDirection = SCROLL_UP;
  14. } else if (firstVisibleItem < mLastTopIndex) {
  15. scrollDirection = SCROLL_DOWN;
  16. } else {
  17. if(top < mLastTopPixel) {
  18. scrollDirection = SCROLL_UP;
  19. } else if(top > mLastTopPixel) {
  20. scrollDirection = SCROLL_DOWN;
  21. }
  22. }
  23. mLastTopIndex = firstVisibleItem;
  24. mLastTopPixel = top;
  25. if (scrollDirection == SCROLL_DOWN) {
  26. } else if (scrollDirection == SCROLL_UP) {
  27. }
  28. }
  29. });

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/289773
推荐阅读
相关标签
  

闽ICP备14008679号