Android devices are so diverse that it's a pain to get your app to fit all the screens, and we need to understand the definition of dimension in Android before we fit in.
How is dimension defined in Android?
Dimension units supported in Android are PX,IN,MM,PT,DP,SP, commonly used to have PX,DP,SP
1. PX
Pixels: Corresponds to the actual pixel on the screen. However, this unit is not recommended because the number of pixels per inch for each device may be different, and the total pixels available on each device screen are different.
2. DP
Density-independent PIXELS:DP is a unit based on the physical density of the screen, which is based on a screen of 160dpi (dots per inch), that is, 1DP is approximately equal to 1px on a 160dpi screen. When running at different dpi, draw on each 1DP or need pixels is not the same, on the screen above 160dpi, and so on, on the contrary, on the screen less than 160dpi, and so on than zoom out. Using DP as a unit will be the simplest way to adapt to different screen densities. This means that DP provides the possibility of unifying UI elements of different sizes.
3. SP
Scale-independent PIXELS:SP Unit is consistent with DP, the difference is that SP units support scale, and when the user adjusts the standard font size in the settings, the PX corresponding to each SP will change.
How is the screen size defined in Android?
Screen Size
That is, the actual physical size, according to the large cell is divided into 4 categories, according to the width of short edge as the subject
XLarge screens is at least 960DP x 720DP
Large screens is at least 640DP x 480DP
Normal screens is at least 470DP x 320DP
Small screens is at least 426DP x 320DP
Screen density
The screen density, which defines the number of PX per DP, is 160dpi standard, 1DP = 1px
LDPI (Low) ~120dpi
MDPI (Medium) ~160dpi
HDPI (High) ~240dpi
XHDPI (Extra-high) ~320dpi
XXHDPI (Extra-extra-high) ~480dpi
XXXHDPI (Extra-extra-extra-high) ~640dpi
Website
Various unit conversions (Https://www.pixplicity.com/dp-px-converter)
px = (dpi/160) * DP
Assuming that the user does not adjust the font size
MDPI corresponds to 160DPI,1DP = 1px = 1SP
Learn more about screen size, units, etc. in Android