问题:在我们使用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>谢谢~
,他们不计后果的彼此拥抱,握紧双手,怕天会亮,怕爱会走。