在学习Android的开发中,学习Gallery视图显示图片的过程中,在设置图片适配器的时候,用到了此TypedArray类型,这次根据android SDK,一块把此类型弄清楚!

android.content.res.TypedArray

包含函数 obtainStyledAttributes(AttributeSet, int[], int, int) 或者 obtainAttributes(AttributeSet, int[])检索的数组值。

在执行完之后,一定要确保调用  recycle()函数 。用于检索从这个结构对应于给定的属性位置到obtainStyledAttributes中的值。

实例:

自定义attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>

java中

//---setting the style
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
                R.styleable.Gallery1_android_galleryItemBackground,0);
a.recycle();

涉及的函数介绍:

obtainStyledAttributes(AttributeSet, int[], int, int)或者

obtainAttributes(AttributeSet, int[])

定义:

public TypedArray obtainStyledAttributes (AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)

public TypedArray obtainAttributes (AttributeSet set, int[] attrs)(说明此函数)

说明:返回一个由AttributeSet获得的一系列的基本的属性值,不需要用用一个主题或者/和样式资源执行样式。

参数:

set:现在检索的属性值;

attrs:制定的检索的属性值

public void recycle()

返回先前检索的数组,稍后再用。

最新文章

  1. poj2492(种类并查集/各种解法)
  2. python图像卷积
  3. $(&#39;#checkbox&#39;).attr(&#39;checked&#39;); 返回的是checked或者是undefined解决办法
  4. [C# 基础知识梳理系列]专题六:泛型基础篇——为什么引入泛型
  5. Android 自定义seekbar中,thumb被覆盖掉一部分问题
  6. 为Angular-UEditor增加工具栏属性
  7. jQuery event,冒泡,默认事件用法
  8. mysql数据库事务详细剖析
  9. UML2和建模工具学习总结
  10. web面试题
  11. ThreadLocal(线程绑定)
  12. 单机版Kubernetes集群(一)
  13. vue中动态加载组件+开发者模式+JS参数值传递和引用传递
  14. C#趋势图(highcharts插件)
  15. win2008 server 多IP配置
  16. C++复习:多态
  17. 自我总结(四) ---java web项目完结,j2ee的开始
  18. struts实现国际化
  19. druapl7:&quot;Notice: A non well formed numeric value encountered 在 _hierarchical_select_hierarchy_generate() &quot;
  20. C实现线程池

热门文章

  1. Android02-Activity01
  2. Landsat8数据不同波段组合的用途
  3. jsonarray-----&gt;list
  4. Struts2 使用通配符动态请求Action
  5. RHEL与Centos
  6. android文件和图片的处理工具类(一)
  7. EBS-利用form个性化 调用报表【Z】
  8. some knowledge
  9. 随记1(#define a 10和const int a=10)
  10. C#时间日期操作