Android ViewPagerIndicator详解及实例代码
程序员文章站
2023-10-21 20:47:25
android viewpagerindicator详解及实例代码
关于自定义view的属性零碎知识
自定义view和自定义属性的知识不再此提及,这里着重说的是属性...
android viewpagerindicator详解及实例代码
关于自定义view的属性零碎知识
自定义view和自定义属性的知识不再此提及,这里着重说的是属性在自定义view中的获取方式,自定义的属性如下:
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="wisely"> <attr name="wisely_1" format="boolean" /> <attr name="wisely_2" format="boolean" /> <attr name="wisely_3" format="boolean" /> <attr name="wisely_4" format="boolean" /> </declare-styleable> <attr name="wisely_out" format="boolean" /> </resources>
自定义view的相关代码如下:
public customview(context context, attributeset attrs) { super(context, attrs); typedarray typedarray = context.obtainstyledattributes(attrs, r.styleable.wisely); typedarray.getboolean(r.styleable.wisely_wisely_1, true); typedarray.recycle(); }
重点看r.styleable.wisely,它返回的是一个数组,而r.styleable.wisely_wisely_1表示的则是数组的索引,它们在r文件中的表示如下:
public static final class attr { public static final int wisely_1 = 0x7f010000; public static final int wisely_2 = 0x7f010001; public static final int wisely_3 = 0x7f010002; public static final int wisely_4 = 0x7f010003; public static final int wisely_out = 0x7f010004; } public static final class styleable { public static final int[] wisely = { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003 }; public static final int wisely_wisely_1 = 0; public static final int wisely_wisely_2 = 1; public static final int wisely_wisely_3 = 2; public static final int wisely_wisely_4 = 3; }
从上面可以看出一点,wisely_out也是attrs.xml中的属性,不过它是写在以wisely命名的标签之外的,所以并未列入到styleable类的wisely数组中。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!