我有一个自定义的ImageView类,我遵循了所有讨论here。但我的应用程序仍然崩溃。我的班级是
public class DrawView extends ImageView {
public DrawView(Context context) {
super(context);
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(getResources().getColor(R.color.lime));
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(3);
canvas.drawRect(touchCornerList.get(0), touchCornerList.get(1),
touchCornerList.get(2), touchCornerList.get(3), paint);
touchCornerList.clear();
}
}
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:focusable="true" >
<DrawView
android:id="@+id/mainImageView"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="10dp"
android:layout_above="@+id/ImageCaptureButton"
android:contentDescription="@string/mainview_description"
/>
</RelativeLayout>
LogCast消息是应用程序无法启动,因为DrawView xml。我的DrawView
有什么问题。
该应用程序在setContentView(R.layout.activity_main);
MainActivity's onCreate()
处崩溃。
感谢。