TypedArray的getResourceId方法 [英] getResourceId method of TypedArray
问题描述
我正在阅读有关 getResourceId()方法.它说:
I am reading docs about getResourceId() method. It says that:
检索索引处属性的资源标识符.笔记当整个TypedArray对象被解析时,该属性资源被解析被检索.结果,此函数将返回资源找到的最终资源值的标识符,不一定属性指定的原始资源.
Retrieves the resource identifier for the attribute at index. Note that attribute resource as resolved when the overall TypedArray object is retrieved. As a result, this function will return the resource identifier of the final resource value that was found, not necessarily the original resource that was specified by the attribute.
所以
- 第一段很清楚:
检索索引处属性的资源标识符.
Retrieves the resource identifier for the attribute at index.
- 第二个也很清楚:
- 但这3段是什么意思? 为什么可以返回 不一定是原始资源ID ?
请注意,当整体TypedArray解析为属性资源时对象被检索.
Note that attribute resource as resolved when the overall TypedArray object is retrieved.
因此,此函数将返回找到的最终资源价值,不一定是原始价值属性指定的资源.
As a result, this function will return the resource identifier of the final resource value that was found, not necessarily the original resource that was specified by the attribute.
推荐答案
从文档:
TypedArray obtainStyledAttributes (AttributeSet set,
int[] attrs,
int defStyleAttr,
int defStyleRes)
....
确定特定属性的最终值时,有四项投入发挥作用:
When determining the final value of a particular attribute, there are four inputs that come into play:
- 给定AttributeSet中的任何属性值.
- 在AttributeSet中指定的样式资源(名为样式").
- defStyleAttr和defStyleRes指定的默认样式
- 此主题的基本值.
这篇关于TypedArray的getResourceId方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!