Android: onScrollStateChanged SCROLL_STATE_IDLE sometimes doesn't fire

前端 未结 3 1712
悲&欢浪女
悲&欢浪女 2021-02-05 23:00

I\'m running into a bit of a problem. What I\'m doing: I\'ve got a ListView which has got some images in it. To make the scrolling smoother I\'ve disabled the images to show up

3条回答
  •  面向向阳花
    2021-02-05 23:03

    I have had this same problem and posted a workaround on the bug list:

    For anybody still running into this problem (as I was last week) a workaround that works for me is the following: If android SDKInt == 7 set a onTouchListener on the (Abs)ListView

    In that onTouchListener when the OnTouch event action is MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL you force a onScrollStateChanged with first a SCROLL_STATE_FLING and then a SCROLL_STATE_IDLE

    Code example: In the onCreate:

      if(androidSDKInt <= 7){
          listViewDateSelector.setOnTouchListener(new FingerTracker(onScrollListener));       }
    

    Then add a private class with:

      private class FingerTracker implements View.OnTouchListener {
          private OnScrollListener myOnScrollListener;
    
          public FingerTracker(OnScrollListener onScrollListener){
              myOnScrollListener = onScrollListener;          }
    
          public boolean onTouch(View view, MotionEvent event) {
              final int action = event.getAction();
              boolean mFingerUp = action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL;
              if (mFingerUp) {
                  myOnScrollListener.onScrollStateChanged((AbsListView) view, OnScrollListener.SCROLL_STATE_FLING);
                  myOnScrollListener.onScrollStateChanged((AbsListView) view, OnScrollListener.SCROLL_STATE_IDLE);
              }
              return false;           }       }
    

提交回复
热议问题