Android 添加自定义ImageView后强制关闭
我试图将自定义的Android 添加自定义ImageView后强制关闭,android,xml,imageview,android-imageview,android-custom-view,Android,Xml,Imageview,Android Imageview,Android Custom View,我试图将自定义的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_pa
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>
此外,如果我在FC之后在调试器中启动程序,我只会得到以下结果:
如果您没有附加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....
如果你没有附加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....
同意,需要第二个构造器。是的,现在它开始工作了。。奇怪的ADT告诉我,我必须包括一个参数,但不包括2。。谢谢这不是ADT,而是Eclipse。同意,需要第二个构造函数。是的,现在它正在工作。。奇怪的ADT告诉我,我必须包括一个参数,但不包括2。。谢谢这不是ADT,而是日食。