解決PhotoView縮放越界的問題

PhotoView是一个老牌的图片缩放框架但是在和ViewPager配合使用的时候,由于多点触控,容易导致越界异常,使APP崩溃!(crashVersion 4.4.4)

百度了一下解决方案很多,我这边的解决方法是定义一个类继承vewpager重写dispatchTouchEvent方法,将异常捕获

@Override  
    public boolean dispatchTouchEvent(MotionEvent ev) {  
           try {  
                  return super .dispatchTouchEvent(ev);  
          } catch (IllegalArgumentException ignored) {  
          } catch (ArrayIndexOutOfBoundsException e) {  
          }  

           return false ;  

   }

下面贴出异常

FATAL EXCEPTION: main
Process: com.yw.zaodao.zhongrb, PID: 13194
java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:2227)
at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:116)
at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:496)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:2058)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2107)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2477)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2477)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2209)
at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:2175)
at android.view.View.dispatchPointerEvent(View.java:8520)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4823)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4674)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4228)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4282)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4251)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4362)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4259)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4419)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4228)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4282)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4251)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4259)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4228)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6643)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6522)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6493)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6458)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6723)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6696)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6742)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
at android.view.Choreographer.doCallbacks(Choreographer.java:613)
at android.view.Choreographer.doFrame(Choreographer.java:581)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:799)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5756)
at java.lang.reflect.Method.invokeNative(Native Method)

                                                                       at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)

你可能感兴趣的:(解決PhotoView縮放越界的問題)