1.px
This is not much of an explanation, it is a physical pixel point on the screen. Eyes good small partner carefully look at the screen should be able to see the small lattice, not a drop of water to see.
It is not recommended to use PX, the same picture may be different on different phone sizes. High resolution display of the small, low resolution of the large display.
2.dp
This unit should be carefully understood, and it is related to pixel density. First say pixel density dpi, which is the number of pixels per inch. If my phone screen size is 1.5 inches x2 inches and the resolution is 240x320, then its pixel density is 160dpi.
The Android system defines 4 resolutions: Low (120DPI), Medium (160DPI), High (240dpi), Ultra High (320DPI), and the corresponding DP-to-PX conversion coefficients are 0.75, 1, 1.5, 2, which multiply by DP length is the number of pixels. If my cell phone pixel density is 240dpi, now there is a picture of 80dp in length, then the pixel length shown is 80x1.5=120px. If my other cell phone pixel density is 320dpi, then the actual pixel length is 160px. In this way, the same pictures on the different phones display the size of almost no difference.
3.dip
Density independent pixels, device independent pixels.
Exactly the same as DP, with different names, no more explanations.
4.sp
Abstract pixels independent of scale (Scale-independent Pixel).
and DP very similar but the only difference is that the Android system allows users to customize the text size (small, normal, large, oversized, etc.), when the text is normal large hours 1SP=1DP, other sizes larger than 1DP or smaller.
Recommendation: text with SP units, other non-text with DP units . For example textsize= "16sp", layout_width= "60DP", occasionally also need to use PX units, such as drawing a split line.
Length units in Android px, DP, SP