• Android--判断listview上下滑动的方法


     1         elv_music_res_fragment.setOnScrollListener(new AbsListView.OnScrollListener() {
     2             private int mLastFirstPostion = 0;
     3             private int mLastFirstTop = 0;
     4             private int touchSlop = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
     5 
     6             @Override
     7             public void onScrollStateChanged(AbsListView view, int scrollState) {
     8 
     9             }
    10 
    11             @Override
    12             public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    13                 int currentTop;
    14 
    15                 View firstChildView = absListView.getChildAt(0);
    16                 if (firstChildView != null) {
    17                     currentTop = absListView.getChildAt(0).getTop();
    18                 } else {
    19                     //ListView初始化的时候会回调onScroll方法,此时getChildAt(0)仍是为空的
    20                     return;
    21                 }
    22                 //判断上次可见的第一个位置和这次可见的第一个位置
    23                 if (firstVisibleItem != mLastFirstPostion) {
    24                     //不是同一个位置
    25                     if (firstVisibleItem > mLastFirstPostion) {
    26                         //
    27                         if (rg_container_resFragment.getVisibility() != View.GONE) {
    28                             rg_container_resFragment.setVisibility(View.GONE);
    29                         }
    30                     } else {
    31                         //
    32                         if (rg_container_resFragment.getVisibility() != View.VISIBLE) {
    33                             rg_container_resFragment.setVisibility(View.VISIBLE);
    34                         }
    35                     }
    36                     mLastFirstTop = currentTop;
    37                 } else {
    38                     //是同一个位置
    39                     if (Math.abs(currentTop - mLastFirstTop) > touchSlop) {
    40                         //避免动作执行太频繁或误触,加入touchSlop判断,具体值可进行调整
    41                         if (currentTop > mLastFirstTop) {
    42                             //
    43                             if (rg_container_resFragment.getVisibility() != View.VISIBLE) {
    44                                 rg_container_resFragment.setVisibility(View.VISIBLE);
    45                             }
    46                         } else if (currentTop < mLastFirstTop) {
    47                             //
    48                             if (rg_container_resFragment.getVisibility() != View.GONE) {
    49                                 rg_container_resFragment.setVisibility(View.GONE);
    50                             }
    51                         }
    52                         mLastFirstTop = currentTop;
    53                     }
    54                 }
    55                 mLastFirstPostion = firstVisibleItem;
    56             }
    57         });
  • 相关阅读:
    HDU 3277 Marriage Match III(最大流+二分+并查集)
    HDU 3032 Nim or not Nim?(博弈,打表找规律)
    2013南京邀请赛小结——ACM两年总结
    HDU 2829 Lawrence (斜率DP)
    HDU 3530 Subsequence(单调队列)
    HDU 1525 Euclid's Game(博弈)
    C Count The Carries(2013南京邀请赛C题)
    A Play the Dice (2013南京邀请赛A题)
    POJ 3017 Cut the Sequence(单调队列+set)
    Jquery TreeView
  • 原文地址:https://www.cnblogs.com/819158327fan/p/6380836.html
Copyright © 2020-2023  润新知