android - Dimen value not working like expected -
i'm having problem understanding dimen resource attribute.
i have 3 value folders: value-normal, value-large , value-xlarge.
i have defined titlesize 20 normal, 25 big , 30 xlarge, normal value file:
<resources> <dimen name="titlesize">20sp</dimen> </resources>
but when seek value
resources r = getresources(); tvtitlesize = r.getdimension(r.dimen.titlesize);
tvtitlesize equal 40 offcourse big. why value double of original , how can prepare this?
ps: device galaxy nexus.
if read docs of resource.getdimension()
method, find this:
resource dimension value multiplied appropriate metric.
in other words getting actual size in pixels device.
the sp density independent value. value corresponds mdpi, galaxy nexus xhdpi, twice dense mdpi. that's why getting 20 * 2 = 40;
if wondering, wrong, reply nothing. size getting correct. actual text size different ldpi/mdpi/hdpi/xhdpi devices.
so illustration 16dp means:
12px on ldpi 16px on mdpi 24px on hdpi 32px on xhdpithe difference between sp
, dp
sp
affected user preference font size.
android
No comments:
Post a Comment