Android layout commonly used units are dip, DP, SP, PX.
Dip/dp
Represents a density-independent pixel (density-independent pixel), which is an abstract unit based on the physical density of the screen. DP is relative to a 160dpi density screen, so the 160dpi density of the screen 1 DP represents a pixel. High screen density unit DP corresponds to high pixel value, low screen density unit DP corresponding pixel value is low. That is, different density of the screen, the unit DP corresponding pixel value is not the same. But remember a little bit, no matter what density, 1 DP on the screen always represents 1/160 inches, so that the different on-screen DP always represent the same size.
Usage scenario: Any scene except fonts
Sp
Represents a scale-independent pixel (scale-independent pixel), which is also a density-independent pixel, which is only affected by the font preference set by the user and follows the font size scaling.
Usage scenario: only in Font size
Px
Represents the pixel (pixel), the actual pixel of the screen.
Usage scenario: Try not to use it, but it can be used in scenes where exactly how many pixels are needed, such as: List Split line height
The following 2 pictures can help you better understand the above layout units
Android Layout Unit Dip DP SP PX