android 在xml文件中引用自定义View
2016-01-13 16:47
453 查看
在xml中引用自定义view
方法一:
[java]
view plaincopy
<com.test.copytext.CopyText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
方法二:
[java]
view plaincopy
<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);
}
方法一:
[java]
view plaincopy
<com.test.copytext.CopyText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
方法二:
[java]
view plaincopy
<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);
}
相关文章推荐
- 关于Android中的onCreate()多次被调用导致bindService被多次调用的问题
- Android String操作
- Android之实现QQ好友分组(ExpandableListView)
- Android Studio乱码问题
- Android5.0 材质设计(纸墨设计)中的z轴理念
- android四大组件---Activity
- Android 蓝牙打印机Service Intent must be explicit
- Android百度定位SDK,返回error code:162 latitude:4.9E-32
- Android开发笔记图片缓存 手势及OOM分析
- Android设置未读消息提示,BadgeView
- Ubuntu下Android开发——配置环境,刷机,push
- 【Android】Android Studio快捷键
- PackageManagerService(Android5.1)深入分析(三)扫描应用目录
- android报错
- 关键词随机飞入飞出效果
- Android开发笔记(四十六)手机相关事件
- android 右滑关闭activity
- android的PowerManager和PowerManager.WakeLock
- Android Studio 使用---(一)Gradle使用手册1
- 关于android instrumentation的理解、使用