PX: is the pixel of the screen
in: inches
MM: millimeter
PT: LB, 1/72 inch
DP: A density-based abstract unit, 1dp = 1px
dip: equivalent to dp
SP: it is similar to DP, but it also scales according to the user's font size preference.
SP is recommended as the unit of text, and dip is recommended for others
The following is an overview of the relationship between DIP and PX:
Qvga screen density = 120; qvga (240*320)
Hvga screen density = 160; hvga (320*480)
WVGA screen density = 240; WVGA (480*800)
wqvga screen density = 120 wqvga (240*400)
the density value indicates the number of display points per inch, and the resolution is two concepts.
screen resolution information under different density, take the WVGA (density = 240) of 480dip * 800dip as an example
density = 120
the actual screen resolution is 240px * 400px (two points correspond to one resolution)
19px or 25dip
the screen width is 400px or 800dip. The height of the working area is 211px or 480dip.
the screen width is PX or dip, working area Height: 381px or 775dip
density = 160
the actual screen resolution is 320px * 533px (three points correspond to two resolutions)
25px or 25dip
the screen width is 533px or 800dip, and the working area height is 295px or 480dip
when the screen is portrait, the screen width is 320px or dip, working area Height: 508px or 775dip
density = 240
the actual screen resolution is 480px * 800px (one point for one resolution)
the status bar and title bar are 38px or 25dip
the screen width is 800px or 800dip, and the height of the working area is 442px or 480dip
when the screen is portrait, the screen width is 480px or 480dip, working area Height: 762px or 775dip
resource package of APK
Resources that use the hdpi label when the screen density is 240
Resources that use the mdpi label when the screen density is 160
Ldpi tag resources are used when the screen density is 120.
Resources without any tags are shared in various resolutions.
Use the unit dip as much as possible during layout, and use less PX
Formula for converting DP to PX:
Pixs
= Dips * (densitydpi/160).
DIPS = (pixs * 160)/densitydpi
DP and PX conversion methods:
Public Static Int Dip2px (Context
Context, float dipvalue ){
Final float Scale = Context. getresources (). getdisplaymetrics (). density;
Return ( Int ) (Dipvalue * Scale + 0 . 5f );
}
Public Static Int Px2dip (Context
Context, float pxvalue ){
Final float Scale = Context. getresource (). getdisplaymetrics (). density;
Return ( Int ) (Pxvalue / Scale + 0 . 5f );
}
VGA: 640*480
Qvga: 320*240
Hvga: 320*480
WVGA: 800*480
Wqvga: 480x272 or 400x240