Android - PX to DP - Wrong height of layout -



Android - PX to DP - Wrong height of layout -

i giving layout height 64dp in layout file , observed mismatch in calculated , actual pixel height.

hdpi device - calculated height - 96 pixels, actual height: 102 pixels xxhdpi device - calculated height - 192 pixels, actual height: 204 pixels

any 1 can help me understand difference in calculated , actual height.

mdpi, hdpi, xhdpi etc "generalized densities". is, dpi groups or ranges.

from android guide:

for illustration 2 devices can have dpi values of 310 , 320 dpi respectively , fall in same group: xhdpi.

the calculations done device code using exact dpi value. while calculations based on dpi groups assume following:

ldpi (low) ~120dpi mdpi (medium) ~160dpi hdpi (high) ~240dpi xhdpi (extra-high) ~320dpi xxhdpi (extra-extra-high) ~480dpi xxxhdpi (extra-extra-extra-high) ~640dpi

update:

the next code:

int widthdp = 160; log.i("test", "actual dpi: " + getresources().getdisplaymetrics().xdpi); float widthdevice = typedvalue.applydimension(typedvalue.complex_unit_dip,widthdp,getresources().getdisplaymetrics()); log.i("test", widthdp + " dip in pixels on device: " + widthdevice);

when run on 2 hdpi devices:

213 dpi device:

2164-2164/com.example.android.dpitest i/test﹕ actual dpi: 213.0 2164-2164/com.example.android.dpitest i/test﹕ 160 dip in pixels on device: 213.0

and 240 dpi device:

2852-2852/com.example.android.dpitest i/test﹕ actual dpi: 240.0 2852-2852/com.example.android.dpitest i/test﹕ 160 dip in pixels on device: 240.0

android android-layout

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -