【Android细节(一)】Gallery设置自定义的背景属性
问题:在我们使用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这个自定义属性:
然后再生成android:GalleryBackground 或android:GalleryItemBackground这两种系统所给属性的GalleryBackground。
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0);
a.recycle();
} 谢谢~