0

I am writing an Android game and I am testing it in two devices at the same time:

  • Huawei P10 Lite: 5.2", 1920x1080, 424dpi, xhdpi.
  • Huawei P40 Pro: 6.58", 2640x1200, 441dpi, xhdpi.

These two devices are utterly different, as they differ in screen size and resolution, but NOT in dpi and dpi bucket; both are xhdpi.

That means regardless the dimen files I create (dimen-mdpi, dimen-hdpi...), any graphic element looks the same in both phones, which completely breaks the layout and proportions in the small phone.

I'm taking this as a reference for bucket classification: enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148
xvlaze
  • 837
  • 1
  • 10
  • 30

1 Answers1

1

Well dpi is all about resolution, and not screen size. If you want to create resources for screen sizes, and not screen resolutions, you should use smalest width qualifiers.

According to the docs:

One DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.

So if I understand correctly, you would convert from pixel to dp by: pixelSize / dip / 160. In this case the formula for your device width in dp is as follows: deviceWidthInPixels / (deviceDip / 160).

  • P10 width in dp: 1080 / (424 / 160) = 407.54
  • P40 width in dp: 1200 / (441 / 160) = 435.37

Looks like other people also came to this conclusion

A. Patrik
  • 1,530
  • 9
  • 20
  • 1
    After is few hours trying I found out creating a custom ```dimens.xml``` file inside a folder named either ```values-sw362``` or ```values-sw363``` did the trick. However, I'm struggling to know where did the 362 come from. – xvlaze Dec 20 '20 at 22:09