ArrayIndexOutOfBoundsException при масштабировании холста в виде прокрутки

Я масштабирую холст и прокручиваю холст внутри прокрутки. Когда вызвано уменьшение масштаба, я получаю ArrayOutOfBoundException.

LogCat:

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 - это класс My Scrollview.

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);
 }
}

Как я могу управлять Multitouch при масштабировании холста в scrollview?

1 ответ

Решение

Я получил решение. Я просто добавил проверку в ACTION_MOVE в onInterceptEvent().

@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;
}
Другие вопросы по тегам