How to properly organize the DP and DPI for each type of screen in Android?

2

Is there any formula or way of knowing the following questions without having to "build up" every time to check?

  • How to know if that Image / Text / Button or whatever is visibly good for the user on the particular screen that has an dpi type?
  • How to know what dp I need to align the Image / Text / Button or whatever is to be correctly in (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
  •   

Density independent pixel: Converting pixel units to screen pixels is simple: px = dp * (dpi / 160)

    
asked by anonymous 22.05.2017 / 16:27

2 answers

3
  

Is there any formula or way of knowing the following questions without having to "build up" every time to check?

There is no "formula" but there is a way to know without "needing to build" all the time .

In the Toolbar of the Layouts Editor tab of Android Studio you have the option to choose the device used to render render .

Itisthuspossibletocheckhowthelayoutappearsonmultipledevices.Youcanalsochoosedeviceorientation,Androidversion,andThemetoapply.

Usingthedpordpidrive(whichisthesamething)ensuresthatviews,margins,padding,etc.arerenderedwiththesamedimensionsregardlessofthescreendensityofthedevice.Thisensuresthat,forexample,abuttonhasthenecessarydimensionstobeclickableorthatthecontentsofanimagecanbenoticeable,regardlessofscreendensity.

Anotherissueistheexistenceofdifferentscreensizes.Itisthedimensionsthatdeterminethenumberofviewsthatcanbeplacedbothverticallyandhorizontally,anditmaybenecessarytocreatealternatelayouts.>

Asacomplement,see Supporting Multiple Screens / Screens .

    
22.05.2017 / 18:04
1

But the concept of DP is just right for this, keeping the same size of views between different screen resolutions. For example, if you have devices with the same aspect ratio (for example, 16: 9) but different resolutions, the views will always appear the same size. Of course, on devices with different aspect ratios, such as a tablet, which is not necessarily 16: 9, the views will not change in size, but will be missing or missing from the app by running on a screen with a different aspect ratio. >

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

    
22.05.2017 / 17:47