How does Android determine screen resolution for so long?

In Android, you can define different resources for different phone attributes by naming res directories accordingly. I need to support various layouts for 480x800 and 480x854 . I decided that I could have one set of resources stored in the layout-hdpi-v4 directory and another in the layout-long-hdpi-v4 directory. However, both resolutions seem to believe that they are long (at least based on an emulator, which, as I understand it, may not accurately reflect the devices).

Is there any other way in which I can distinguish between two resolutions / proportions?

+3
source share
2 answers

There is a screen size determinant , although its use is outdated and it is recommended not to use it:

layout-800x480 , layout-854x480

Otherwise, it does not seem that the resource names have a supported method that can distinguish between two resolutions, in addition to using flexible layouts to expand into additional screen space.

+3
source

If you want to determine the size of the screen in the code, DisplayMetrics will help

 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); 

You can see the widthPixels and heightPixels .

However, read also "Best Practices for Screen Independence."

+2
source

Source: https://habr.com/ru/post/1346047/


All Articles