問題:在我們使用Gallery作爲前端佈局,需要
1、先使用TypeArray自定義屬性類
2、再通過TypeArray對象調用getResourceId()得到android:GalleryBackground或android:GalleryItemBackground格式。
但是android:GalleryBackground或android:GalleryItemBackground 這個格式在android包內本身依然存在,爲什麼不直接調用android:GalleryBackground或android:GalleryItemBackground格式呢?
是因爲在創建TypeArray對象時,android:R.styleable在SDK1.5中已經不再支持。
所以需要我們創建R.styleable.Gallery這個自定義屬性:
<span style="font-size:18px;"> <?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery">
<attr name="android:galleryItemBackground">
</attr>
</declare-styleable>
</resources></span>
然後再生成android:GalleryBackground 或
android:GalleryItemBackground這兩種系統所給屬性的GalleryBackground。
<span style="font-size:18px;"> public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0);
a.recycle();
} </span>
謝謝~