小编Lei*_*sen的帖子

自定义ImageView崩溃程序

我正在为Android制作一个小应用程序,我有一个RelativeLayout,其中包含一个自定义ImageView.在我的Java代码中,我有这个类:

package com.example.android.helloactivity;


class ArrowImageView extends ImageView {
    public ArrowImageView(Context context) {
        super(context);
    }
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(10,10,10,null);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的RelativeLayout xml中,我有以下内容:

<RelativeLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:background="#FFF"
            xmlns:android="http://schemas.android.com/apk/res/android">
    <Button ...... />
    <TextView ......./>

    <com.example.android.helloactivity.ArrowImageView
        android:id="@+id/hello_activity_bearingarrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

当我运行我的主类(此处未显示)时,我的程序崩溃了.如果我省略了对ArrowImageView的xml引用,那么它不会崩溃.

我指的是我的自定义类te错误的方式,或者发生了什么?

android android-layout

5
推荐指数
1
解决办法
2337
查看次数

标签 统计

android ×1

android-layout ×1