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

当手指在SwitchButton上面移动,然后move出了SwitchButton的边界,移动到其他控件上面,还能滑动SwitchButton #51

Closed
t2314862168 opened this issue Jun 3, 2016 · 1 comment

Comments

@t2314862168
Copy link

看了一下代码在move里面没有加边界判断,超出控件自身范围后,应该和UP里面的执行一样的逻辑吧

switch (action) {
            case MotionEvent.ACTION_DOWN:
                catchView();
                mStartX = event.getX();
                mStartY = event.getY();
                mLastX = mStartX;
                setPressed(true);
                break;

            case MotionEvent.ACTION_MOVE:
                float x = event.getX();
                setProcess(getProcess() + (x - mLastX) / mSafeRectF.width());
                mLastX = x;
                break;

            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                setPressed(false);
                nextStatus = getStatusBasedOnPos();
                float time = event.getEventTime() - event.getDownTime();
                if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) {
                    performClick();
                } else {
                    if (nextStatus != isChecked()) {
                        playSoundEffect(SoundEffectConstants.CLICK);
                        setChecked(nextStatus);
                    } else {
                        animateToState(nextStatus);
                    }
                }
                break;

            default:
                break;
        }
@kyleduo
Copy link
Owner

kyleduo commented Jun 3, 2016

这是Android事件机制决定的,同时由于SwitchButton自身比较小,这个特性也使得使用者误操作的几率大大降低。也建议你尝试一下原生的Switch,以及其他应用的做法。

@kyleduo kyleduo closed this as completed Jun 3, 2016
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