美文网首页
(转)NestedScrollView中首次点击无效

(转)NestedScrollView中首次点击无效

作者: 匡风含情 | 来源:发表于2017-01-10 19:41 被阅读138次

    stackoverflow:http://stackoverflow.com/questions/31829976/onclick-method-not-working-properly-after-nestedscrollview-scrolled/32783524

    It is a bug of the NestedScrollView, the detail of the bug can be found in here: issue. The problem is that mScroller.isFinished() in onInterceptTouchEvent(MotionEvent ev) will not return true after a fling operation (even if the fling is stopped). Therefore the touch event is intercepted.

    This bug have been reported for a while, but still have not been fixed. So I have created by own version of bug fix for this problem. I implemented my own NestedScrollView, copied all the code from NestedScrollView and having the with the following amendments:

    public class NestedScrollView extends FrameLayout implements NestedScrollingParent, NestedScrollingChild {
        ...
        private void initScrollView() {
            ...
            // replace this line:
            // mScroller = new ScrollerCompat(getContext(), null);
            mScroller = ScrollerCompat.create(getContext(), null);
            ...
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            ...
            switch (action & MotionEventCompat.ACTION_MASK) {
                ...
                case MotionEvent.ACTION_DOWN: {
                    ...
                    // replace this line:
                    // mIsBeingDragged = !mScroller.isFinished();
                    mIsBeingDragged = false;
                    ...
                }
            }
        }
       
    }
    

    And this NestedScrollView should have the same behaviour as the original one.

    相关文章

      网友评论

          本文标题:(转)NestedScrollView中首次点击无效

          本文链接:https://www.haomeiwen.com/subject/taqlbttx.html