使用TouchImageView(外部类)进行带图像的手势

时间:2015-02-05 05:50:44

标签: android imageview

我尝试使用我在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.access$800(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)

是因为我错误地使用了这门课程吗?

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

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

1 个答案:

答案 0 :(得分:0)

这样做:

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

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

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