Android’s ‘Density-Independent Pixel’

Android devices have wildly-varying pixel-per-inch resolutions. To aid developers, the OS offers a “density-independent pixel” unit of measurement:

A virtual pixel unit that applications can use in defining their UI, to express layout dimensions or position in a density-independent way.

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dip units needed, based on the actual density of the screen in use. The conversion of dip units to screen pixels is simple: pixels = dips * (density / 160). For example, on 240 dpi screen, 1 dip would equal 1.5 physical pixels. Using dip units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

I suspect Apple will do something similar, except that by going straight from 480 × 320 to 960 × 640, everything just doubles in terms of pixels and nothing works out to a non-integer scaling factor.

Monday, 19 April 2010

Ads via The Deck Ads via The Deck