Why does the dp-to-pixel ratio change with screen density, but not necessarily in direct proportion

I am a little worried about what I read here , from which it follows that there is no reliable formula for calculating pxbased on dpand screen density (and vice versa):

dp: Density-independent pixels — An abstract block based on the physical density of the screen. These units refer to a 160 dpi (dots per inch) screen, on which 1dp is approximately 1px. When working on a screen with a higher density, the number of pixels used to draw 1dp increases by a factor suitable for the screen. Similarly, when on a screen with a lower density, the number of pixels used for 1dp decreases. The dp-to-pixel ratio will vary with screen density, but not necessarily in direct proportion.Using dp units (instead of pixel units) is an easy solution to create view sizes in your layout, correctly resize for different screen densities. In other words, it ensures that your user interface is consistent in size across devices in the real world.

I thought we could always use the following formula (explained here ): px = dp * (dpi / 160)

However, the evidence in this matter seems to highlight the case where specifying sizes in dpdoes not guarantee a fixed perceived size on all devices.

What is the real meaning of the sentence in bold? Should it be used mmin order to maintain the same perceived size?

0
1

, ( ): px = dp * (dpi/160)

dp. , DisplayMetrics.densityDpi dpi .

, , , , dp .

, , dp . , . , Dpi ( ) dpi . . , .

dp-to-pixel ,

, , " ", , .

, dpi 270 (240) dp-- 240/160 = 1,5

290 "xhigh" (320) dp-to-pixel 320/160 = 2

, 7% (270 → 290), dp-to-pixel 33% (1,5 → 2), .

, ?

, , . , , .

, , , . Lint () () ?

+1

All Articles