http://blog.youkuaiyun.com/centralperk/article/details/8669247
在xml中引用自定义view
方法一:
- <com.test.copytext.CopyText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
方法二:
- <view class="com.test.copytext.CopyText"
- 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);
}
本文讨论了在XML中引用自定义View时可能遇到的常见错误,并提供了解决这些问题的方法,包括检查包名和确保自定义View的构造方法。
3361

被折叠的 条评论
为什么被折叠?



