【发布时间】:2014-08-22 21:43:30
【问题描述】:
我有一些看法,并想以像素为单位获取高度。我从构造函数调用
attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "layout_height", -1)
总是得到默认值,但是
attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height")
正常工作。 attrs.getAttributeIntValue 有什么问题?
【问题讨论】:
-
正常工作是什么意思?你得到了什么价值?
-
您不应该直接使用 AttributeSet,而应该使用 TypedArray,有关更多信息,请参阅 AttributeSet 文档
-
当我从视图中获取自定义参数时,我通常使用 TypedArray,但现在我只需要“layout_height”
-
@user3165616 所以创建一个只包含一个值的 int 数组:android.R.attr.layout_height