So I have android 2.3.5 device which is NORMAL/HDPI. I have a dimens.xml in my project:
...
20sp
Just to clarify (information obtained by inspecting Android source code):
Resources.getDimension()
and getDimensionPixelOffset()
/getDimensionPixelSize()
differ only in that the former returns float
while the latter two return the same value rounded to int
appropriately. For all of them, the return value is in raw pixels.
All three functions are implemented by calling Resources.getValue()
and converting the thus obtained TypedValue
by calling TypedValue.complexToDimension()
, TypedValue.complexToDimensionPixelOffset()
and TypedValue.complexToDimensionPixelSize()
, respectively.
Therefore, if you want to obtain the "raw" value together with the unit specified in the XML source, call Resources.getValue()
and use the methods of the TypedValue
class.