1.自定義控件時仗处,可以通過TypedArray attrs獲取布局文件中設(shè)置的屬性值呼股。再獲取某一條屬性值前档叔,可以通過attrs.hasValue(R.styleable.屬性名)判斷是否包含該屬性容握。
代碼示例:
if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
if (null != colors) {
setTextColor(colors);
}
}```
2.獲取第一個可見子View
public int getFirstVisibleItemPosition() {
if (mLinearLayout == null) {
return 0;
}
//獲取小圖標(biāo)的數(shù)量
int size = mLinearLayout.getChildCount();
for (int i = 0; i < size; i++) {
View view = mLinearLayout.getChildAt(i);
//當(dāng)出現(xiàn)小圖標(biāo)的x軸比當(dāng)前ScrollView的x軸大時哨颂,這個小圖標(biāo)就是當(dāng)前可見的第一個
if (getScrollX() < view.getX() + mItemWidth / 2.0F)
return i;
}
return 0;
}
3.Library Module中不能使用Switch方式操作resouce id。因為在SDK tools r14之后這些id是non final的小腊,要操作需要使用if-else救鲤,AS中有快捷鍵轉(zhuǎn)換。
持續(xù)更新ingV雀浴1静!