0
我使用GitHub here,它可以讓您輕鬆放大imageViews。但他們有一個問題,如果ImageView在ViewGroup中會導致應用程序崩潰。所以他們提出了一種解決方法,當我將解決方法代碼實施到我的項目中時,它並不奏效。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類來自this的GitHub這裏,並在錯誤的另一行代碼也變爲這樣:
public class LeftDrawerLayout extends ViewGroup {
...
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mHelper.shouldInterceptTouchEvent(ev);
}
...
這個程序是在Nexus 6 V6.0.1測試
當我把catch改成'Exception'時,我仍然得到一個錯誤 –
我實際上修復了一些其他問題,並使用這段代碼修復了我原來的問題!謝謝! (請查看[this](https://github.com/chrisbanes/PhotoView/issues/382)以獲得更深入的解釋,以幫助我解決其他人的問題!) –