我已将pinchzoom.jar库添加到我的项目中以允许捏合和缩放图像。并添加了以下代码 -
try {
usingSimpleImage(imageView);
}
catch(Exception e) {
}
public void usingSimpleImage (ImageView imageView){
try {
ImageAttacher mAttacher = new ImageAttacher(imageView);
// ImageAttacher.MAX_ZOOM = 2.0f; // Double the current Size
// ImageAttacher.MIN_ZOOM = 0.5f; // Half the current Size
MatrixChangeListener mMaListener = new MatrixChangeListener();
mAttacher.setOnMatrixChangeListener(mMaListener);
PhotoTapListener mPhotoTap = new PhotoTapListener();
mAttacher.setOnPhotoTapListener(mPhotoTap);
}
catch(Exception e)
{
System.out.println("exception");
}
}
private class PhotoTapListener implements OnPhotoTapListener {
@Override
public void onPhotoTap(View view, float x, float y) {
}
}
private class MatrixChangeListener implements OnMatrixChangedListener {
@Override
public void onMatrixChanged(RectF rect) {
}
}
当我快速捏合和缩放并且我的应用程序崩溃时,我有以下异常 -
Exception dispatching input event.
10-11 19:31:10.734 31507-31507/com.peoplecloud.guggu E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:1981)
at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1839)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1833)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2244)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1949)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2244)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1949)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2244)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1949)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2244)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1949)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1938)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1392)
at android.app.Activity.dispatchTouchEvent(Activity.java:2408)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1886)
at android.view.View.dispatchPointerEvent(View.java:7323)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3521)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3455)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4544)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4523)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4619)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4598)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4638)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:747)
at android.view.Choreographer.doCallbacks(Choreographer.java:567)
at android.view.Choreographer.doFrame(Choreographer.java:534)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:733)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
可能面临与https://github.com/chrisbanes/PhotoView/issues/4相同的问题。
解决方法是尝试捕获错误:
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
try {
return super.onInterceptTouchEvent(event);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return false;
}
}