カスタム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);
}
}
また、FCの後にデバッガーでプログラムを開始した場合、私はこれを手に入れるだけです。テキストをリンクします
解決
Androidのソースコードを添付していない場合、デバッガーは役に立ちません。さらに... LogCat出力を提供する方が便利です。とにかく、私はあなたがコンストラクターの1つが欠けていると思います。これを試して:
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