当继承View的时候,会有个一个含有AttributeSet参数的构造方法,通过此类就可以得到自己定义的xml属性,也可以是android的内置的属性,方法如下:

//取得xml中自己定义的属性值

Log.e(tag, "attrs.getAttributeValue(\"\", \"myAttribute\"):"+attrs.getAttributeValue(null, "myAttribute"));attrs.getAttributeValue(null, "myAttribute")




//取得系统自带的属性值

Log.e(tag, "attrs.getAttributeValue(\"\", \"android:layout_height\"):"+attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_width"));attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_width")



http://schemas.android.com/apk/res/android:为android XML的namespace


布局XML中配置自定义View:

<cc.mdev.test.EnlargeView android:id="@+id/bit" android:layout_width="fill_parent"android:layout_height="fill_parent" myAttribute="My Hello"/>


更多相关文章

  1. Android——自定义左右菜单的实现
  2. Android(安卓)MTP模式切换分析
  3. android――资源目录
  4. Android(安卓)Studio使用小技巧:自定义Logcat
  5. Android学习笔记——常用的基本UI组件及其常用属性值和相关方法
  6. android 中Bn 和Bp的区别
  7. android 自定义radiobutton的样式 实现自己想要的样子
  8. 【Android(安卓)Training UI】创建自定义Views(Lesson 2 - 自定
  9. [置顶] Android:自定义View实现水波进度效果

随机推荐

  1. SQLServer 附加数据库后出现只读或失败的
  2. SQL 合并多行记录的相同字段值
  3. MSSQL Server 查询优化方法 整理
  4. mysql 数据库中索引原理分析说明
  5. SQL批量插入数据几种方案的性能详细对比
  6. SQL数据库的高级sql注入的一些知识
  7. 分享网站群发站内信数据库表设计
  8. SQL高级应用之使用SQL查询Excel表格数据
  9. 用sql语句实现分离和附加数据库的方法
  10. Cont()与Where().Count()有时性能差别如