【Android细节(一)】Gallery设置自定义的背景属性
2015-03-22 22:07
621 查看
问题:在我们使用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:GalleryItemBackground这两种系统所给属性的GalleryBackground。
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>谢谢~
相关文章推荐
- Android进阶篇-自定义Menu(设置Menu的背景及文字属性)
- Android进阶篇-自定义Menu(设置Menu的背景及文字属性)
- Android自定义属性为应用程序设置全局背景
- android 自定义Dialog背景透明及显示位置设置
- 【Android】如何在自定义View中设置自定义的属性
- android在自定义View的xml中设置自定义的成员属性
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置的方法
- Android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- Android之自定义背景Button按钮、自定义形状Button的全攻略、设置字体颜色
- Android自定义圆形调色板,可设置属性
- android开发之自定义TextView设置字间距以及通过TextView控件属性设置行间距
- android 自定义控件,自定义属性设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- 自定义AlertDialog的实现以及添加属性设置背景
- android 自定义Dialog背景透明及显示位置设置