إغلاق الإغلاق بعد إضافة ImageView مخصص
-
28-09-2019 - |
سؤال
أحاول إضافة مخصص ImageView
لي main.xml
, ، ولكن إذا بدأت البرنامج ، فإنه يغلق بإغلاق قسري.
XML
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" >
<test.testpkg.CustomImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:src="@drawable/bg"/>
</LinearLayout>
Java
:
package test.testpkg;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.ImageView;
public class CustomImageView extends ImageView {
public CustomImageView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
أيضًا إذا بدأت البرنامج في Debugger بعد FC ، أحصل على هذا فقط:نص الارتباط
المحلول
Debugger عديمة الفائدة إذا لم تكن قد أرفقت رمز Android المصدر. علاوة على ذلك ... من المفيد توفير إخراج logcat. على أي حال ، أعتقد أنك تفتقد أحد المنشئين. جرب هذا:
public class CustomImageView extends ImageView {
public CustomImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
// rest of your code....
لا تنتمي إلى StackOverflow