将 TouchImageView(外部 class)用于带有图像的手势

Using TouchImageView (external class) for gestures with image

我尝试使用在 https://github.com/MikeOrtiz/TouchImageView

中找到的 TouchImageView

但是我得到一个错误:

02-05 12:46:05.508: E/AndroidRuntime(21710): FATAL EXCEPTION: main
02-05 12:46:05.508: E/AndroidRuntime(21710): Process: com.km.parkit, PID: 21710
02-05 12:46:05.508: E/AndroidRuntime(21710): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.km.parkit/com.km.parkit.MainMap}: java.lang.ClassCastException: android.widget.ImageView cannot be cast to com.km.parkit.TouchImageView
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread.access0(ActivityThread.java:144)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.os.Looper.loop(Looper.java:135)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread.main(ActivityThread.java:5221)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at java.lang.reflect.Method.invoke(Native Method)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at java.lang.reflect.Method.invoke(Method.java:372)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-05 12:46:05.508: E/AndroidRuntime(21710): Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to com.km.parkit.TouchImageView
02-05 12:46:05.508: E/AndroidRuntime(21710):    at com.km.parkit.MainMap.onCreate(MainMap.java:16)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.Activity.performCreate(Activity.java:5933)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-05 12:46:05.508: E/AndroidRuntime(21710):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

是不是我用错了class?

我在另一个名为 MainMap 的 class 中使用了它:

TouchImageView image;
image = (TouchImageView) findViewById(R.id.overview);

这样做:

TouchImageView img = (TouchImageView) findViewById(R.id.img);

如果您在xml中使用TouchImageView,那么您必须提供完整的包 名称,因为它是自定义视图。示例:

<com.km.parkit.TouchImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />