Px
Pixel (pixel), which represents a physical pixel point on the screen
It is not recommended to use the px
drawing UI directly, because the px
actual size displayed on different phones will be different for the UI drawn for units affected by pixel density
DP (used to define the size of the control)
Density-independent pixels. One of the virtual pixel units that Android recommends is to have the same effect on a device with a defined UI layout at a different pixel density.
Pixel density dpi = number of pixels per inch length = Screen portrait (landscape) Length/Number of screen portrait (landscape) pixels.
This density-independent pixel size is equivalent to dpi
a physical pixel on the screen. So px = dp * (dpi / 160)
.
The Android system defines four pixel densities:
name |
abbreviation |
DPI |
low |
ldpi |
Approx. 120dpi |
medium |
mdpi |
Approx. 160dpi |
high |
hdpi |
Approx. 240dpi |
extra-high |
xhdpi |
Approx. 320dpi |
extra-extra-high |
xxhdpi |
Approx. 480dpi |
extra-extra-extra-high |
xxxdpi |
Approx. 640dpi |
Dip
dp
The early naming, and dp
exactly the same.
SP (for defining font size)
Scale independent pixels (scale-independent pixel). sp
and dp
very similar but the difference is that theAndroid system allows users to customize text size (small, normal, large, oversized, and so on), when the text size is "normal" when the 1 sp
=1 dp
, and when the text size is "large" or "super-large" When, 1 sp
>1 dp
.
Therefore sp
, it is mainly used to define the font size, and when the user sets the magnification font, only the text in the SP is magnified .
Pt
Standard length unit, 1 pt
=1/72 inch = 0.035 cm.
Inch
inches, 1 inches = 2.54 cm (approx.)
Various scale units in Android development