android 在xml文件中引用自定义View
生活随笔
收集整理的這篇文章主要介紹了
android 在xml文件中引用自定义View
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在xml中引用自定義view
方法一:
[java] view plaincopy方法二:
[java] view plaincopy
?
在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);
??? }
總結
以上是生活随笔為你收集整理的android 在xml文件中引用自定义View的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态添加综合布局---动态添加控件及将某
- 下一篇: Android中自定义View的研究 -