Android 在scrollview中缩放画布时的ArrayIndexOutOfBoundsException

Android 在scrollview中缩放画布时的ArrayIndexOutOfBoundsException,android,canvas,scrollview,multi-touch,pinchzoom,Android,Canvas,Scrollview,Multi Touch,Pinchzoom,我正在缩放画布并在scrollview中滚动画布。当调用zoom out时,我得到了BoundException的ArrayOutOfBoundException 日志: java.lang.ArrayIndexOutOfBoundsException at android.view.MotionEvent.getY(MotionEvent.java:792) at android.widget.ScrollView.onInterceptTouchEvent(ScrollView.java:4

我正在缩放画布并在scrollview中滚动画布。当调用zoom out时,我得到了BoundException的ArrayOutOfBoundException

日志:

java.lang.ArrayIndexOutOfBoundsException
at android.view.MotionEvent.getY(MotionEvent.java:792)
at android.widget.ScrollView.onInterceptTouchEvent(ScrollView.java:419)
at com.example.pinchzoom.CustomVerticalScrollView.onInterceptTouchEvent(CustomVerticalScrollView.java:120)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:902)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1878)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1159)
at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1862)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1809)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
CustomVerticalScrollView是我的Scrollview类


在scrollview中缩放画布时如何管理多点触控?

我得到了解决方案。我刚刚在ACTION\u MOVE in onInterceptEvent()中添加了验证

public class CustomVerticalScrollView extends ScrollView {

private GestureDetector mGestureDetector;

Context context;

public CustomVerticalScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    this.context = context;
}

// true if we can scroll the ScrollView
// false if we cannot scroll
private boolean scrollable = true;

/**
 * This method used for setScrolling to ScrollView
 * 
 * @param is
 *            True in onInterceptTouchEvent returns true else false
 * 
 * */
public void setScrollingEnabled(boolean scrollable) {
    this.scrollable = scrollable;
}

/**
 * Check is scrollview isScrollable or not
 * */
public boolean isScrollable() {
    return scrollable;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    //
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // if we can scroll pass the event to the superclass
        if (scrollable)
            return super.onTouchEvent(ev);
        // only continue to handle the touch event if scrolling enabled
        return scrollable;
        // scrollable is always false at this point
    default:
        return super.onTouchEvent(ev);
    }
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    // Don't do anything with intercepted touch events if
    // we are not scrollable
    if (!scrollable)
        return false;
    else
        return super.onInterceptTouchEvent(ev);
 }
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Don't do anything with intercepted touch events if
// we are not scrollable
switch (action) {
    case MotionEvent.ACTION_MOVE:
        if (scrollable) {
            // We're currently scrolling, so yes, intercept the
            // touch event!
            return true;
        }

        return false;
}