Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上下滑动 列表 有时会触发OnItemClick事件 ,几率出现 #9

Open
ta893115871 opened this issue Sep 19, 2015 · 3 comments
Open

Comments

@ta893115871
Copy link

上下滑动 列表 有时会触发OnItemClick事件 ,几率出现

@hongyangAndroid
Copy link
Owner

的确存在上述问题,我暂时没时间修复,如果你有好的方案,欢迎PR。我会尽量抽空看下。

@ta893115871
Copy link
Author

private boolean isSticky;//mNav-view 是否悬停的标志
在dispatchTouchEvent方法里增加
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP://处理悬停后立刻抬起的处理
float distance = y - mLastY;
if(isSticky && /distance==0.0f/Math.abs(distance) <= mTouchSlop){
isSticky=false;
return true;
}else{
isSticky=false;
return super.dispatchTouchEvent(ev);
}
在onTouchEvent 方法里修改 like this

// 如果topView隐藏,且上滑动时,则改变当前事件为ACTION_DOWN
if (getScrollY() == mTopViewHeight && dy < 0) {
event.setAction(MotionEvent.ACTION_DOWN);
dispatchTouchEvent(event);
isInControl = false;
isSticky=true;
}else{
isSticky=false;
}

并修改dispatchTouchEvent 方法
case MotionEvent.ACTION_MOVE:
float dy = y - mLastY;
getCurrentScrollView();

            if (mInnerScrollView instanceof ScrollView) {
                if (mInnerScrollView.getScrollY() == 0 && isTopHidden && dy > 0
                        && !isInControl) {
                    isInControl = true;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                    MotionEvent ev2 = MotionEvent.obtain(ev);
                    dispatchTouchEvent(ev);
                    ev2.setAction(MotionEvent.ACTION_DOWN);
                    isSticky=true;
                    return dispatchTouchEvent(ev2);
                }
            } else if (mInnerScrollView instanceof ListView) {

                ListView lv = (ListView) mInnerScrollView;
                View c = lv.getChildAt(lv.getFirstVisiblePosition());

                if (!isInControl && c != null && c.getTop() == 0 && isTopHidden
                        && dy > 0) {
                    isInControl = true;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                    MotionEvent ev2 = MotionEvent.obtain(ev);
                    dispatchTouchEvent(ev);
                    ev2.setAction(MotionEvent.ACTION_DOWN);
                    isSticky=true;
                    return dispatchTouchEvent(ev2);
                }
            }
            break;

即对isSticky赋值

经测试可以修改此bug!!!!忘楼主有时间看下可以不?嘻嘻

@ta893115871
Copy link
Author

看下面这个解决了此问题
https://github.com/ta893115871/StickyNavLayout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants