Android DP to PX conversion, is 160 dp always 160 px on mdpi? -


i'm getting lost in unfortunate ambiguity regarding http://developer.android.com/guide/practices/screens_support.html, , can't find stackoverflow answer clarifies issue.

i aware of documentation claims:

the density-independent pixel equivalent 1 physical pixel on 160 dpi screen, baseline density assumed system "medium" density screen. @ runtime, system transparently handles scaling of dp units, necessary, based on actual density of screen in use. conversion of dp units screen pixels simple: px = dp * (dpi / 160). example, on 240 dpi screen, 1 dp equals 1.5 physical pixels. should use dp units when defining application's ui, ensure proper display of ui on screens different densities.

what @ issue definition of 'dp' in formula. based on graphic little further down page, seems "actual density" mdpi-class device spans range of values, 120 200. mean 160 dpi map anywhere between 120 200 pixels mdpi-class device? or mdpi-class device convert 160 dpi 160 pixels?

according this post dianne hackborn, indeed case. "compatible" android device cannot have non-standard density:

in theory android can scale density , show ui match exact density of screen. in practice don't -- we have defined handful of specific densities support , require compatible devices stick them. why this?

the first reason our developers. ui designers tend make nice clean graphics; these graphics drawn bitmaps, , giving designers small set of target bitmap sizes support instead of infinite variation makes things lot simpler them.

(...)

so android defines few major buckets of density values devices can use, called ldpi (approx 120dpi), mdpi (160 dpi), hdpi (240 dpi), , xhdpi (320 dpi). manufacturers can select density appropriate device, long results in screen (after scaling density) within minimum allowed screen size of platform.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -