Conceptual interpretation
Noun |
Explain |
Px (Pixel pixels) |
Different devices show the same effect. The "Same" here means that the number of pixels does not change, such as specifying a UI length of 100px, regardless of the resolution of the UI length is 100px. This is why the UI is magnified and distorted on small-resolution devices, and is scaled down at large resolutions. |
Screen Size (Screen size) |
Generally speaking, the size of a mobile phone screen, such as 1.6-inch, 1.9-inch, 2.2-inch, refers to the length of the diagonal, not the phone area. We can get the width and length of the phone according to the Pythagorean theorem, and of course the area. |
Resolution Resolution |
Refers to the number of pixels in the vertical and horizontal direction of the phone's screen. For example, the resolution is 480*320, which means that the device has a vertical orientation of 480 pixels and a horizontal 320 pixel point. |
dpi pixel density) |
Note: This value corresponds to the value in the displaymetrics class for properties densitydpi . For details, refer to http://www.cnblogs.com/wader2011/archive/2011/11/28/2266669.html |
density (density) |
density=resolution/screen size density * Density = (Resolution width * Resolution height)/(screen Width * screen height) note: In the displaymetrics class, the properties The density has a value of dpi/160 , which you can use for px The and Dip are converted to each other. For details, refer to http://www.cnblogs.com/wader2011/archive/2011/11/28/2266684.html |
Dip (device-independent pixel, device independent pixels) |
With DP, can be used as a unit of length, different devices have different display effect , this and equipment hardware, generally we in order to support WVGA, HVGA and QVGA recommend this, do not rely on pixels. The corresponding formula for dip and specific pixel values is the dip value =pixel value/density. |
Sp (Scaledpixels Enlarge pixels) |
Mainly used for font display (best for TEXTSIZE). According to Google's suggestion, TextView's font size is best to use SP to do units, and view the source of TextView know that Android by default using the SP as the font size units. |
Summarize
We can use the following ideas to explain why the dip instead of PX units:
- The device will end up with PX as the unit of length.
- If we use PX directly as a unit it will cause the UI to appear inappropriate scaling on different resolution devices. So we need a new unit that will eventually be able to convert the appropriate coefficients into PX to make the UI appear the right size.
- Does the dip meet this requirement?
The corresponding formula of the dip and the specific pixel value of the dip value =pixel value/density can be known
Pixel value =dip value *denstiy , where the dip value is the length size we specify, then the pixel value, that is, the final UI pixel value is only affected by the density densitiy, the denstiy is equivalent to that conversion factor, the value of this coefficient is the number of devices to decide. The dip therefore meets this requirement.
The SP can also understand this.
Turn: http://www.cnblogs.com/wader2011/archive/2011/11/29/2267490.html adjustment inside formula error.
Description of the PX dpi dip density densitydpi in Android