带有 SwipeBack 的 PhotoView(用于缩放)不起作用

PhotoView(for zooming) with SwipeBack not working

我有一个 activity,我必须在其中显示具有缩放功能的图像,并且我需要在向下拖动它时关闭 activity,就像在 facebook 应用程序中发生的那样。我正在使用 PhotoView by Chris Banes for image zooming and SwipeBack 通过向下拖动来关闭 activity。这是我的 activity :

public class AlternateFullImageActivity extends SwipeBackActivity {
    String photoId;
    String token;
    TinyDB tinyDB;
    RestAdapter restAdapter;
    @Bind(R.id.zoomable)
    ImageView image;
    @Bind(R.id.swipe_layout)
    SwipeBackLayout swipeBackLayout;
    PhotoViewAttacher mAttacher;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alternate_full_image);
        setDragEdge(SwipeBackLayout.DragEdge.TOP);

        ButterKnife.bind(this);

        tinyDB = new TinyDB(this);
        token = tinyDB.getString("Galleri5 Access Token");

        Intent intent = getIntent();
        photoId = intent.getExtras().getString("ID");

        RequestInterceptor requestInterceptor = new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader("Accept", "application/json");
                request.addHeader("Authorization", "Token " + token);
            }
        };
        OkHttpClient okHttpClient = new OkHttpClient();
        restAdapter = new RestAdapter.Builder()
                .setClient(new OkClient(okHttpClient))
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setEndpoint(API)
                .setRequestInterceptor(requestInterceptor)
                .build();

        PhotoAPI photoAPI = restAdapter.create(PhotoAPI.class);
        photoAPI.getFeed(photoId, new Callback<ImageItem>() {
            @Override
            public void success(ImageItem imageItem, Response response) {
                Picasso.with(AlternateFullImageActivity.this)
                        .load(imageItem.getPhotoUrl())
                        .into(image);
                mAttacher = new PhotoViewAttacher(image);
            }

            @Override
            public void failure(RetrofitError error) {

            }
        });
    }

}

这是我的布局文件:

<com.liuguangqiang.swipeback.SwipeBackLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.galleri5.android.activities.AlternateFullImageActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <uk.co.senab.photoview.PhotoView
        android:id="@+id/zoomable"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

</RelativeLayout>

</com.liuguangqiang.swipeback.SwipeBackLayout>

当我 运行 这个时,一切正常,但是当我缩小图像时,我得到这个错误:

11-05 14:23:37.125 3506-3506/com.galleri5.android E/InputEventReceiver: Exception dispatching input event.
11-05 14:23:37.126 3506-3506/com.galleri5.android E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1014)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.liuguangqiang.swipeback.SwipeBackLayout.onInterceptTouchEvent(SwipeBackLayout.java:248)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2059)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2569)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1743)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2530)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.View.dispatchPointerEvent(View.java:8578)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4028)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3894)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3585)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3642)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5708)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5682)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5653)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5798)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.os.MessageQueue.nativePollOnce(Native Method)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.os.MessageQueue.next(MessageQueue.java:143)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.os.Looper.loop(Looper.java:122)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at android.app.ActivityThread.main(ActivityThread.java:5254)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at java.lang.reflect.Method.invoke(Native Method)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at java.lang.reflect.Method.invoke(Method.java:372)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
11-05 14:23:37.130 3506-3506/com.galleri5.android E/MessageQueue-JNI:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime: FATAL EXCEPTION: main
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime: Process: com.galleri5.android, PID: 3506
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1014)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.liuguangqiang.swipeback.SwipeBackLayout.onInterceptTouchEvent(SwipeBackLayout.java:248)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2059)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2569)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1743)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2530)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.View.dispatchPointerEvent(View.java:8578)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4028)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3894)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3585)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3642)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5708)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5682)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5653)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5798)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.os.MessageQueue.nativePollOnce(Native Method)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.os.MessageQueue.next(MessageQueue.java:143)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:122)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
11-05 14:23:37.172 3506-3506/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

之后,我阅读了有关 PhotoView 的信息,并按照 github 页面中的说明,尝试为 SwipeBackLayout 创建一个 Hacky 布局。这是代码:

import com.liuguangqiang.swipeback.SwipeBackLayout;

public class HackySwipeBackLayout extends SwipeBackLayout {
    public HackySwipeBackLayout(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return false;
        }
    }
}

然后我使用新的 HackySwipebackLayout 替换了早期的布局文件。

但是在那之后,当我 运行 应用程序并单击图像转到上面 activity 时,我收到此错误:

11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime: FATAL EXCEPTION: main
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime: Process: com.galleri5.android, PID: 6709
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.galleri5.android/com.galleri5.android.activities.AlternateFullImageActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class com.galleri5.android.utils.HackySwipeBackLayout
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.access0(ActivityThread.java:147)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:  Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class com.galleri5.android.utils.HackySwipeBackLayout
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:616)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.liuguangqiang.swipeback.SwipeBackActivity.setContentView(SwipeBackActivity.java:21)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.galleri5.android.activities.AlternateFullImageActivity.onCreate(AlternateFullImageActivity.java:48)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5933)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.access0(ActivityThread.java:147) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:  Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.Class.getConstructor(Class.java:531)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.Class.getConstructor(Class.java:495)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:580)
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.liuguangqiang.swipeback.SwipeBackActivity.setContentView(SwipeBackActivity.java:21) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.galleri5.android.activities.AlternateFullImageActivity.onCreate(AlternateFullImageActivity.java:48) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5933) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.access0(ActivityThread.java:147) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 
11-05 14:28:22.245 6709-6709/com.galleri5.android E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 

这可能是什么原因以及如何让它发挥作用?我真的需要它来工作。谢谢。

java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]

您的 HackySwipeBackLayout 缺少构造函数:

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

如果你仔细看看 HackyViewPager, you'll notice that it is in there too. As a matter of fact, any view that needs to support inflating from xml should have this constructor defined. You may find the documentation on how to create custom views 也很有帮助。


编辑:由于您的意图是捕获抛出的异常,因此请确保相应地捕获 ArrayIndexOutOfBoundsException

@Override public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {
        return super.onInterceptTouchEvent(ev);
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
        return false;
    }
}

这应该会阻止您的应用程序因这个特定异常而崩溃,但当然不是 'fix' 导致首先抛出 ArrayIndexOutOfBoundsException 的根本问题。它可能会或可能不会导致所需的行为。无论哪种方式,请考虑与 SwipeBack 存储库的维护者一起打开 ticket