1.DP (DIP): Different devices have different display effect, this is related to the device hardware, generally we support WVGA,HVGA and QVGA to the sword Use this, it is not dependent on pixels
2.px:pixels (pixels), different devices display the same effect, generally we hvga represent 320x480 pixels, this use more
3.pt:point, is a standard length unit, 1pt=1/72 inches, for printing, very easy to use
4.sp:scaled pixels (enlarged pixels), mainly used for font display best for TEXTSIZE
In the APK's resource bundle, use the hdpi tag when the screen density=240
When the screen desity=160, the resource using the MDPI tag
Resources that use ldoi tags when the screen is density=120
On a 160-point monitor, 1dp=1px
5. The following is the conversion of the different units in the focus:
1 Public Static intDIP2PX (Context context,floatdipvalue) {2 Final floatScale =context.getresources (). Getdisplaymetrics (). density;3 return(int) (Dipvalue * scale + 0.5f);4 }5 Public Static intPx2dip (Context context,floatpxvalue) {6 Final floatScale =Context.getresource (). Getdisplaymetrics (). density;7 return(int) (Pxvalue/scale + 0.5f);8 }9 Public Static intDIP2PX (Context context,floatdipvalue) {Ten Final floatScale =context.getresources (). Getdisplaymetrics (). density; One return(int) (Dipvalue * scale + 0.5f); A } - Public Static intPx2dip (Context context,floatpxvalue) { - Final floatScale =Context.getresource (). Getdisplaymetrics (). density; the return(int) (Pxvalue/scale + 0.5f); -}
6. Here's how to get the resolution:
1 //In an activity's OnCreate method, write the following code:2Displaymetrics metric =Newdisplaymetrics ();3 Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metric);4 intwidth = metric.widthpixels;//screen width (pixels)5 intHeight = metric.heightpixels;//screen height (pixels)6 floatdensity = metric.density;//screen Density (0.75/1.0/1.5)7 intdensitydpi = metric.densitydpi;//screen density dpi (120/160/240)
The 7.Android supports all of the following units.
PX (pixels): The point on the screen.
In (inches): unit of length.
MM (mm): unit of length.
PT (lb): 1/72 inches.
DP (density-independent pixels): An abstract unit based on screen density. 1DP = 1px on a monitor 160 dots per inch.
Dip: Same as DP, more for android/ophone example.
SP (scale independent pixels): Similar to DP, but can be scaled based on user's font size preference