首页 > 移动平台 > 详细

【Android细节(一)】Gallery设置自定义的背景属性

时间:2015-03-23 09:34:11      阅读:388      评论:0      收藏:0      [点我收藏+]


问题:在我们使用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>
谢谢~

【Android细节(一)】Gallery设置自定义的背景属性

原文:http://blog.csdn.net/qq_22939165/article/details/44543085

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!