ViewGroup 使应用程序崩溃

ViewGroup crashes app

我正在使用 GitHub here,它可以让您在 imageViews 上轻松放大。但是他们有一个问题,如果 ImageView 在 ViewGroup 中,它会使应用程序崩溃。所以他们提出了一个解决方法,当我将解决方法代码实施到我的项目中时,它没有工作。

建议代码:

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.mxn.soul.flowingdrawer_core.LeftDrawerLayout;

/**
 * Created by user on 2016-06-28.
 */
public class HackyProblematicViewGroup extends LeftDrawerLayout {

public HackyProblematicViewGroup(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {
        return super.onInterceptTouchEvent(ev);//The error first goes here then to the LeftDrawerLayout on the bottom!
    } catch (IllegalArgumentException e) {
        //uncomment if you really want to see these errors
        //e.printStackTrace();
        return false;
    }
}
}

错误信息:

06-28 16:07:51.764 614-614/com.wilsapp.wilsapp E/ViewDragHelper: Ignoring pointerId=1 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because  ViewDragHelper did not receive all the events in the event stream.
06-28 16:07:51.772 614-614/com.wilsapp.wilsapp E/InputEventReceiver: Exception dispatching input event.
06-28 16:07:51.772 614-614/com.wilsapp.wilsapp D/AndroidRuntime: Shutting down VM
06-28 16:07:51.789 614-614/com.wilsapp.wilsapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.wilsapp.wilsapp, PID: 614
                                                             java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
                                                                 at android.support.v4.widget.ViewDragHelper.saveLastMotion(ViewDragHelper.java:849)
                                                                 at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1057)
                                                                 at com.mxn.soul.flowingdrawer_core.LeftDrawerLayout.onInterceptTouchEvent(LeftDrawerLayout.java:212)
                                                                 at com.wilsapp.wilsapp.HackyProblematicViewGroup.onInterceptTouchEvent(HackyProblematicViewGroup.java:22)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
                                                                 at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
                                                                 at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
                                                                 at android.app.Activity.dispatchTouchEvent(Activity.java:2771)
                                                                 at com.wilsapp.wilsapp.Buyer_Home_Page.dispatchTouchEvent(Buyer_Home_Page.java:410)
                                                                 at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
                                                                 at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
                                                                 at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
                                                                 at android.view.View.dispatchPointerEvent(View.java:9520)
                                                                 at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
                                                                 at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
                                                                 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
                                                                 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
                                                                 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
                                                                 at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
                                                                 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
                                                                 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
                                                                 at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)
                                                                 at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)
                                                                 at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)
                                                                 at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6025)
                                                                 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:5996)
                                                                 at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6048)
                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                 at android.view.Choreographer.doFrame(Choreographer.java:600)
                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                at android.os.Handler.handleCallb

我是我添加的代码错了还是?

另外,LeftDrawerLayout class来自this GitHub这里,错误中的另一行代码也转到了这个:

public class LeftDrawerLayout extends ViewGroup {
...
    @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return mHelper.shouldInterceptTouchEvent(ev);
}
...

此应用已在 Nexus 6 v6.0.1 上测试

ArrayIndexOutOfBoundsException 不是 IllegalArgumentException 的子类。尽管如果您真的想捕获该异常,可以将 IllegalArgumentException 替换为 Exception.