我使用dispatchTouchEvent通过以下代码做出滑动手势

@Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        boolean result = super.dispatchTouchEvent(ev);
        // disable the gesture in this screen because we have
        return gDetector.onTouchEvent(ev);
    }


我想使用SignatureView捕获客户签名
https://github.com/CoatedMoose/CustomViews/blob/master/library/src/com/coatedmoose/customviews/SignatureView.java
所以我想在用户单击SignatureView时禁用滑动手势,我该怎么做?

最佳答案

我对SignatureView项目不熟悉,但是对于常规的GesturDetector,您可以像下面这样将事件传递给GestureDetector,仅当它在其“目标” View范围内时:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

    boolean result = super.dispatchTouchEvent(ev);

    if (inSignatureArea(ev)) {
        return gDetector.onTouchEvent(ev);
    }
    else {
        return result;
    }
}

public boolean inSignatureArea(MotionEvent ev) {
    float eventX = ev.getX();
    float eventY = ev.getY();
    return (eventX > signatureArea.getX() && eventX < (signatureArea.getX() + signatureArea.getWidth())) ;
    // && (same thing for Y and height);
}


您应该能够使其适应您的需求。

10-08 14:25