How to properly organize DP and DPI for each screen type on Android?

Asked

Viewed 5,047 times

2

Is there any kind of formula or way to know the following questions without having to "build" all the time to check?

  • How to know if that Image/Text/Button or whatever is visibly good for the user on the given screen that has a type of dpi?
  • How to know which dp I need to align the Image/Text/Button or whatever it is to be correctly on (Header, Footer, Center, Right or Left) correctly for each screen.

The knowledge I have is as follows:

  • ldpi (low) ~ 120 dpi
  • mdpi (average) ~ 160 dpi
  • hdpi (high) ~ 240 dpi
  • xhdpi (extra-high) ~ 320 dpi
  • xxhdpi (extra-extra-high) ~ 480 dpi
  • xxxhdpi (extra-extra-extra-high) ~ 640 dpi

Pixel density independent (dp): Conversion of pixel units to screen pixels is simple: px = dp * (dpi / 160)

2 answers

3


Is there any kind of formula or way to know the following questions without having to "build" all the time to check?

There is no "formula" but there is a way to know without "need to stay "building" all the time".

In the Toolbar of the Editor tab layouts Android Studio has the option to choose the device used to do the surrender of layout.

inserir a descrição da imagem aqui

It is thus possible to check how the layout is displayed on multiple devices. There is also the possibility to choose the orientation of the device, the Android version and the Theme to be applied.

The use of the dp or dpi unit (which is the same thing) ensures that views, margins, padding, etc are rendered with the same dimensions, whatever the screen density of the device. This ensures that, for example, a button has the dimensions necessary to be clickable or that the content of an image can be perceived, whatever the screen density.

Another issue is the existence of different screen sizes. It is its dimensions that determine the number of views that can be placed both vertically and horizontally, there may be situations that will require the creation of layouts alternative.

As a complement see How to support various types of screens/screens.

  • I understand regarding checking without compiling using the preview of the layous editor on Android Stúdio itself. But the problem is I’m using an augmented reality SDK called vuforia. And in the layout the screen is all black, because I’m using a "camera" layout where the camera of the phone stays on. I have no way to check by Layout or AVD, because AVD builda certinho but does not open the emulator, nothing happens. How to fix this?

  • I have no experience with vuforia, so I can’t help you. Expose this problem in a new question.

1

But the concept of PD is just made for this, keep the same size of the views between different screen resolutions. For example, if you have devices with the same screen ratio (for example, 16:9) but different resolutions, the view will always appear the same size. Of course, on devices with different screen proportions, like a tablet, which is not necessarily 16:9, the views will not change size, but will remain or lack screen compared to the app running on a screen with different ratio.

You can test various screen settings in Android Studio itself without compiling. In the preview screen of the layouts editor you can always change the target device in the combobox of this window that shows the name of a device.

  • I understand regarding checking without compiling using the preview of the layous editor on Android Stúdio itself. But the problem is I’m using an augmented reality SDK called vuforia. And in the layout the screen is all black, because I’m using a "camera" layout where the camera of the phone stays on. I have no way to check by Layout or AVD, because AVD builda certinho but does not open the emulator, nothing happens. How to fix this?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.