I. Unit of measure (DP,SP,PX)
is the abbreviation for pixels, which is the usual pixel unit, corresponding to the point on the screen.
On screens with different resolutions, the dimensions of the components using PX as units will be inconsistent. Components of the same PX, the larger the resolution, the smaller the actual display size
The DP (density-independent Pixel) is a density-independent pixel unit, or dip. It is an abstract unit based on the physical density of the device screen. 1DP Indicates the length of 1px at the screen DPI . DPI (dots per inch | pixels per inch) the higher the screen, the more pixels the screen draws 1DP needs , and vice versa.
In different resolutions of the screen, using DP as unit components, the dimensions are consistent.
The SP (scale-independent pixel) is a pixel unit that is independent of scale . Similar to DP, the only difference is that the unit is affected by the system font settings and is usually used in fonts.
Android Specifies the common size of the font in the design specification:
Micro 12SP, small 14sp, medium 18sp, large 22SP
Screen size. The screen size is the physical size of the diagonal of the phone , in inches (inch). 1 inch = 2.54 cm, so the diagonal length of the 5 inch phone 5*2.54=12.7 cm
720*1280 means that the screen has 720 pixels in the width direction and 1280 pixels in the height direction
- Density (dpi,dots per inch or PPI, pixels per inch)
Pixels per inch, the higher the value, the more delicate the display. To 5 inch mobile phone,1080*1920 resolution to calculate: by the above resolution knowledge points, the number of diagonal pixels by the Pythagorean theorem , about 2203, 2203 divided by 5 inches is the screen density, the result is 440dpi
On the mdpi screen (i.e. 160DPI), 1DP and 1sp are basically equal to 1px
Conversion formula for DP and px: PX = dp* (dpi/160) SP and px conversion formula: px = sp* (dpi/160)
Second, the Android screen adaptation
Android screen adaptation