在学习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 styleTypedArray 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. Android(安卓)actionbar在Material主题中修改样式
  2. android 基础控件(EditView、SeekBar等)的属性及使用方法
  3. Android(安卓)SipDemo项目实现SIP协议
  4. Android应用程序安装与Launcher启动机制
  5. android备份服务流程
  6. Android(安卓)如何解析Xml字符串
  7. Android启动过程详解(4)——SystemServer
  8. Android(安卓)Binder Mechanism (3) -- 如何向系统注册Service
  9. 解决Android(安卓)TextView,Button 字母大写问题

随机推荐

  1. android学习日志(一)
  2. Android(安卓)中的WiFi学习笔记
  3. android github 知名库
  4. android IPC及原理简介
  5. android 焦点问题
  6. android 网络访问-图片处理优秀开源项目
  7. Android7.0 MTK方案 静默安装和卸载
  8. 设置TextView文字居中
  9. 使用ProgressBar实现进度条
  10. Android布局属性全面剖析