我想我的自定义ImageView
添加到XML布局。Android的自定义组件布局
的main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.android.gag.TouchImageView
android:id="@+id/Image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="center" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
TouchImageView
,正如它的名字所暗示的,extends
的ImageView
类。
Main.java
touchImageView = (TouchImageView)findViewById(R.id.Image1);
我的应用程序崩溃。 logcat的输出:
10-16 20:38:20.275: E/AndroidRuntime(11354): FATAL EXCEPTION: main
10-16 20:38:20.275: E/AndroidRuntime(11354): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gag/com.android.gag.Main}: android.view.InflateException: Binary XML file line #6: Error inflating class com.android.gag.TouchImageView
10-16 20:38:20.275: E/AndroidRuntime(11354): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
idRuntime(11354): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.android.gag.TouchImageView
10-16 20:38:20.275: E/AndroidRuntime(11354): at android.view.LayoutInflater.createView(LayoutInflater.java:589)
10-16 20:38:20.275: E/AndroidRuntime(11354): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
请,任何人都可以帮助我吗? 我是初学者,所以像'replace "class library" with "Android library project"'这样的答案是毫无意义的,因为它们太模糊,我不知道从哪里开始以及去哪里。
编辑:链接到我的TouchImageView class
请你说明你的TouchImageView的实现。 – Daniel
https://dl.dropbox.com/u/43107774/TouchImageView.java – Teo
当您错误地重写ImageView的方法时,通常会发生此问题。 – Daniel