Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android the definition density-independent pixels

Tags:

android

I am new to android. I read about DP but m still confused. In one definition it says- dp (density-independent pixels): An abstract unit based on the density of the screen. On a display with 160 dots per inch, 1dp = 1px.

does it mean- 160 dots=1 dp = 1 px (each dot is 1 pixel , right?) OR 1 dp = 1 dot(pixel) among the 160 dots

Pleas clarify

like image 980
Tanvir Avatar asked Sep 01 '12 05:09

Tanvir


People also ask

What is density-independent pixels Android?

To preserve the visible size of your UI on screens with different densities, you must design your UI using density-independent pixels (dp) as your unit of measurement. One dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density screen (160dpi; the "baseline" density).

What is the meaning of PPI pixel density?

Pixels per inch (PPI) is the measure of resolution in a digital image or video display. Pixels per inch (PPI) is typically used to refer to the display resolution, or pixel density, of a computer monitor or screen. The greater the pixels per inch (PPI), the greater the detail in the image or display.

How much PPI is good for mobile?

In principle as the resolution of the phone display increases so should the PPI. As a rough guide, for a 6-inch full HD (1920 x 1280) phone you're looking at approximately 390 pixels per inch and for a 7-inch QHD+ (2960 x 1440) smartphone expect around 480 PPI.


1 Answers

density-independent pixels is a virtual pixel unit that you should use when defining UI layout, 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, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:

px = dp * (dpi / 160)

For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

For 160 dpi screen 1 dp equals 1 px.

Refer to this blog and this answer.

like image 184
Jainendra Avatar answered Nov 06 '22 16:11

Jainendra