Android自定义VIEW取得XML的自定义值
2011年08月01日
当继承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.getAttributeVal ue("http://schemas.android.com/apk/res/android", "layout_width")); attrs.getAttributeValue("http://schemas.android.co m/apk/res/android", "layout_width")
http://schemas.android.com/apk/res/android:为android XML的namespace
布局XML中配置自定义View:
2011年08月01日
当继承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.getAttributeVal ue("http://schemas.android.com/apk/res/android", "layout_width")); attrs.getAttributeValue("http://schemas.android.co m/apk/res/android", "layout_width")
http://schemas.android.com/apk/res/android:为android XML的namespace
布局XML中配置自定义View:
本文介绍如何在Android自定义View中通过构造方法获取XML布局文件中的自定义属性值和系统内置属性值。文中提供了具体的代码示例,包括如何使用AttributeSet来获取属性。
7462

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



