Dip:device independent pixels (device independent pixel). Different devices have different display effects, this is related to the device hardware, we generally support WVGA, HVGA and QVGA CWJ recommended Use this, do not rely on pixels.
Px:pixels (Pixel). Different devices display the same effect, generally we hvga represent 320x480 pixels, this use more.
Pt:point, is a standard length unit, 1pt=1/72 inches, used in the printing industry, is very simple and easy to use;
sp:scaled pixels (zoom in pixels). Mainly used for font display best for textsize.
Thus, according to Google's proposal, TextView's font size is best to use SP to do units, and view
TextView
The source code that Android uses the SP as the default font size unit.
###################################################################
About conversions (Take SP and PT for example)
See TextView and other types of source code, know:
Case COMPLEX_UNIT_PX:
return value;
Case COMPLEX_UNIT_SP:
return value * metrics.scaleddensity;
Case COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0F/72);
--------------------------
Scaleddensity = Density_device/(float) density_default;
xdpi = Density_device;
--------------------------
Density_default = Density_medium = 160;
============================================
So: If the PT and SP take the same value of 1, you can set the coefficient of x between 1pt and 1SP,
1 * density_device/72 = x * 1 * density_device/160 =>
x = 160/72 = 2.2222
Which means that in Android, 1pt is about 2.22SP.
For reference, if the UI can provide the design in the SP as the best, if the design does not have an SP
, developers can also use the appropriate conversions to get an approximate value.
This article links http://www.cxybl.com/html/wyzz/CSS/20120614/30134.html