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

来源:互联网 发布:二战伪军数量知乎 编辑:程序博客网 时间:2024/04/29 16:30
<item name="text_line_spacing" type="dimen" format="float">1.2</item>
<item name="top_weight" type="dimen" format="integer">5</item>

要在xml中引用上述定义的dimens,可以使用@dimen/text_line_spacing。 
要在代码中引用上述定义的dimens,可以使用如下代码。

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。


本文出自:http://m.blog.csdn.net/blog/ccpat/45671095
转载请注明!
0 0