您的位置:首页 > 移动开发 > Android开发

今天学一招 android dimen中设置不带单位的数值

2015-11-02 20:28 549 查看
[code]<item name="text_line_spacing" type="dimen" format="float">1.2</item>

[code]

[code]
<item name="top_weight" type="dimen" format="integer">5</item>
要在xml中引用上述定义的dimens,可以使用@dimen/text_line_spacing。
要在代码中引用上述定义的dimens,可以使用如下代码。
[code]TypedValue outValue = new TypedValue();
getResources().getValue(R.dimen.text_line_spacing, outValue, true);
float value = outValue.getFloat();
注意:不能通过getResources().getDimension(R.dimen.text_line_spacing);方式来引用,如果用这种方式引用上述方法定义的dimens,编译时不会报错,但是运行时会抛出NotFoundException。

[code]本文出自:http://m.blog.csdn.net/blog/ccpat/45671095

[code]转载请注明!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: