0

I am a bit confused regarding the conversion of dp to px and px to dp. The formula goes this way

px = dp*(dpi/160)

Let's consider two screens A & B of densities of 160 dpi and 320 dpi respectively. This itself means that in the same area B has more number of pixels than A which means the pixel size of 160dpi screen should be larger for the same screen size and should be equal to the physical size of 2 pixels of 320dpi screen. But, putting in the formula for B this gives that 1 pixel for B is equivalent to the physical size of 2 density independent pixels or 2 pixels of 160dpi screen. What am I missing here?

Shubham
  • 175
  • 3
  • 12

1 Answers1

0

Try to understand the scaling system with this example. Pretend you have a bitmap you want to display 48dp x 48dp big on each screen (independently from density). We have:

  • mDPI, 160dpi screen (ratio 1x) --> bitmap: 48x48 px (old devices)
  • hDPI, 240dpi screen (ratio 1.5x) --> bitmap: 72x72 px (48 x 1.5)
  • xhDPI, 320dpi screen (ratio 2x) --> bitmap: 96x96 px (48 x 2)
  • xxhDPI, 480dpi screen (ratio 3x) --> bitmap: 144x144 px (48 x 3)
  • xxxhDPI, 640dpi screen (ratio 4x) --> bitmap: 192x192 px (48 x 4)

In a nutshell, to answer your question, you have a different amount of pixels for different densities but the same number of dps.

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64