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數組中。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
|
新聞熱點
疑難解答