我想将我的自定义添加ImageView
到 xml 布局中。
主.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);
我的应用程序崩溃。日志输出:
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)
请问,谁能帮帮我?我是初学者,所以像''用“Android 库项目”替换“类库” ''这样的答案是没有意义的,因为它们太模糊了,我不知道从哪里开始,去哪里。
编辑:链接到我的TouchImageView 类