[Screen Adaptation] The relationship between pixel density and resolution dp px

1. What is pixel density

  • The number of pixels per inch. The unit is dpi.

2. The relationship between dp and px

  • Android stipulates that when the screen pixel density is 160dpi, 1dp=1px. In the case of a pixel density of 320dpi, 1dp=2px, and so on.
  • 1dp = dpi/160px. That is, on a 320dpi mobile phone, 1dp is equivalent to 2px.

3. What do resolution, screen size, and pixel density mean?

  • Resolution: Resolution (resolution, referred to as resolution by Hong Kong and Taiwan) is the precision of the screen image, which refers to the number of pixels that the monitor can display. For example: 1080px * 1920px means that the screen width is 1080 pixels, the height is 1920 pixels, and a screen can display a total of 2073600 pixels.
  • Note: Only when the screen size is the same, the higher the resolution, the finer and delicate the display effect will be. Affected by the dot pitch of the picture tube, the higher the resolution, the clearer it is not necessarily.
  • According to the formula in 2, the higher the pixel density, the finer it should be
  • Screen size refers to the length of the diagonal, in inches.
  • Pixel density = number of pixels on the diagonal of the screen ➗ diagonal inches

Example:

Xiaomi MIX2 has a resolution of 1080*2160 and a size of 6 inches. What is the pixel density?

  • To find the pixel density, you need to know the length of the diagonal
  • The length of the diagonal of the screen is the evaluation of the hypotenuse of the triangle. Hypotenuse = √(screen width px² + screen height px²) = 402.5dpi
  • That is, 1px = 160/402.5dp = 0.4dp on this phone. Therefore, the length of 100px in the UI design draft is 40dp on Xiaomi MIX2.

Summarize:

  • Pixel density is related to resolution and screen size.
  • The same dp value, such as 40dp, displays different pixel lengths on mobile phones with different dpi. Actual display px = 40 * (actual dpi/160) px

Guess you like

Origin blog.csdn.net/u011084603/article/details/122130289