2014-06-18 4 views
0

나는 캔버스를 확대하고 스크롤 뷰 내부에서 캔버스를 스크롤하려고합니다. 축소라고하면 ArrayOutOfBoundException이 발생합니다.ArrayIndexOutOfBoundsException 스크롤 할 때 캔버스를 확대 할 때

로그 캣 :

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 클래스입니다.

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

있는 ScrollView에 캔버스를 확대 할 때 나는 멀티 터치를 관리 할 수 ​​있습니까?

답변

0

나는 해결책을 얻었습니다. 나는 onInterceptEvent()에서 ACTION_MOVE에 유효성 검사를 추가했습니다.

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