<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.youkuaiyun.com/blog/ccpat/45671095
转载请注明!