經常使用getAttributeIntValue()方法,但是大多使用的形式是attrs.getAttributeFloatValue(null, "xxx", 0);只是在中間傳一個字符串,來獲取屬性值
今天突然看到某程序的源碼中,三個參數都傳入了值。網上找attrs.getAttributeFloatValue方法的詳解,結果都不是很滿意。從android源碼中找到如下信息。
正文,具體的使用場景就不多說了,主要說該方法的參數解析
getAttributeIntValue()--通常--需要傳入3個參數,分別是
String namespace, String attribute, int defaultValue
namespace是命名空間。
attribute是在布局文件中所寫的屬性
defaultvalue是當通過getAttributeIntValue()去查找時,沒有找到相應的值,值默認返回defaultvalue。
Android API文檔如下
public abstract int getAttributeIntValue (String namespace, String attribute, int defaultValue)
Added in
API level 1
Return the integer value of 'attribute'.
Parameters
| namespace | Namespace of attribute to retrieve. |
|---|---|
| attribute | The attribute to retrieve. |
| defaultValue | What to return if the attribute isn't found. |
Returns
- Resulting value.
