Wednesday, April 20, 2011

Android - Supporting Multiple Screens



Screen Size


      Android collapses all actual screen sizes into four generalized sizes: small, normal, large, and extra large. Applications can provide custom layouts for each of these four sizes — the platform transparently handles the rendering of the layouts at the actual screen size.

Density-independent pixel (dp)

     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. At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. 

The conversion of dp units to screen pixels is simple:

              pixels = dps * (density / 160).

     For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens