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