场景:自定义一个View,并在XML文件中管理的时候引用自定义View
主要原因有两个:
①XML引用View的时候没有把完整的包名添加上去
<com.chenjunhan.basictest.unit.MyView
android:layout_width="match_parent"
android:layout_height="match_parent" />
②这个错误有点细微,查了好多资料才懂
在自定义的View类中,需要重写View的一系列构造方法,其中有两个是必须重写的:
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyView(Context context,AttributeSet set) {
super(context,set);
// TODO Auto-generated constructor stub
}