在xml中引用自定义view
方法一:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
方法二:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="aaaaaaaaaaaa"
/>
在xml文件中间引用自定义view时遇到了这个错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{cm.test/cm.test.TestsActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.test.testview
这就需要查看在xml中引用时的包名是否正确
还可能会遇到这个错:11-24 10:58:38.993: ERROR/AndroidRuntime(323): Caused by: java.lang.NoSuchMethodException: HelloView(Context,AttributeSet)
这是因为自定义View中缺少了一个构造方法
public HelloView(Context context,AttributeSet attrs){
super(context, attrs);
}