Android definition of independent pixel density

I am new to android. I read about DP, but I'm still confused. One definition says: dp (density independent pixels): an abstract block based on screen density. Display with 160 dpi, 1dp = 1px.

Does this mean 160 points = 1 dp = 1 px (each point is 1 pixel, right?) OR 1 dp = 1 point (pixel) among 160 points

Please clarify

+7
source share
2 answers

Density-independent pixels are a virtual pixel element that you should use when defining a user interface layout to express the size or position of the layout regardless of density.

A density-independent pixel is equivalent to one physical pixel on a screen with a resolution of 160 dpi, which is the base density accepted by the system for a medium-density screen. During operation, the system transparently processes any scaling of dp blocks as necessary, based on the actual density of the screen used. Converting dp blocks to screen pixels is simple:

px = dp * (dpi / 160)

For example, on a screen with a resolution of 240 dpi, 1 dp is equal to 1.5 physical pixels. You should always use dp modules when defining the user interface of an application to ensure that your interface displays correctly on screens with different densities.

For a screen with a resolution of 160 dpi, 1 dp is 1 px.

Refer to this blog and this answer.

+14
source

The Android documentation has -

A density-independent pixel is equivalent to one physical pixel on a screen with a resolution of 160 dpi, the base density adopted by the platform (as described later in this document). During operation, the platform transparently handles any scaling of the required dp units based on the actual density of the screen used. Converting dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on a screen with a resolution of 240 dpi, 1 dp will be equal to 1.5 physical pixels. Using dp modules to define application user interfaces is highly recommended as a way to ensure that your user interface displays correctly on different screens.

You can see multi-screen support . You can also take a look at this question .

0
source

All Articles