The unit of measurement for Android PX,IN,MM,PT,DP,DIP,SP

Source: Internet
Author: User

Android in Dip, DP, PX, SP and screen density 1. Dip:device independent pixels (device independent pixels). Different devices have different display effects, this is related to the device hardware, generally we support WVGA, HVGA and QVGA recommended use this, do not rely on pixels.
It is important to note that dip is related to screen density and that the screen density is related to specific hardware and that the hardware settings are incorrect and may cause the dip to not display properly. On the screen density of 160 display, 1dip=1px, sometimes your screen resolution is very large, such as 480*800, but the screen density is not set correctly for example or 160, then all the use of dip will show the anomaly, the basic display is too small.
Dip conversion:
Dip (value) = (int) (PX (value)/1.5 + 0.5)
2. DP: Very simple, and dip is the same.
3. Px:pixels (pixels), different devices different display display effect is the same, this is absolute pixels, is how much will never change.
4. sp:scaled pixels (enlarge pixels). Mainly used for font display of best for textsize.

Note: According to Google's recommendation, pixels uniformly use the dip, the font unified use SPFor example, the difference between PX and dip:px pixels, if using PX, will be used to draw the actual pixel, than a bar, with a line length of 240px, in the 480 wide simulator is half the screen width, and in the 320 wide simulator is 2/3 of the screen width. Dip, that is, the height of the screen is divided into 480 points, the width divided into 320 points. For example, you make a 160dip horizontal line, whether you are in 320 or 480 of the simulator, is half the length of the screen.
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.getresources (). Getdisplaymetrics (). density;
return (int) (Pxvalue/scale + 0.5f);
}

PX: Is the pixel point of the screen
In: Inch
MM: MM
PT: lbs, 1/72 inch
DP: An abstract unit based on density, if a 160dpi screen, 1dp=1px
Dip: Equivalent to DP
SP: similar to DP, but also scaled according to the user's font size preference.
It is recommended to use SP as the unit of text, other dip


Dip and PX Relationships:
qvga:density=0.75;     densitydpi=120; QVGA (240*320)

hvga:density=1.0;     densitydpi=160; HVGA (320*480)

vga:density=1.0;     densitydpi=160; VGA (480*640)

wvga:density=1.5;     densitydpi=240; WVGA (480*800)

wqvga:density=2.0;     densitydpi=120; WQVGA (240*400)

The Densitydip value represents the number of display points per inch, and the resolution is two concepts

Screen resolution information under different densitydpi, with 480dip*800dip WVGA (density=240) as an example

When densitydpi=120

Screen actual resolution is 240px*400px (two points corresponds to a resolution)

Status bar and title bar height 19px or 25dip

Screen width 400px or 800dip, working area height 211px or 480dip

Screen width 240px or 480dip when vertical screen, working area height 381px or 775dip

densitydpi=160

Screen actual resolution is 320px*533px (3 points corresponds to two resolutions)

Status bar and title bar tall 25px or 25dip

Screen width 533px or 800dip, working area height 295px or 480dip

Screen width 320px or 480dip when vertical screen, working area height 508px or 775dip

densitydpi=240

Screen actual resolution is 480px*800px (one point for one resolution)
Status bar and title bar tall 38px or 25dip
Screen width 800px or 800dip, working area height 442px or 480dip
Screen width 480px or 480dip when vertical screen, working area height 762px or 775dip

APK in the resource bundle

Resources that use HDPI tags when the screen is densitydpi=240

Resources that use MDPI tags when the screen is densitydpi=160

Resources that use LDPI tags when the screen is densitydpi=120

Resources that are not tagged are shared in a variety of resolution cases

Use unit dip as much as possible in layout, use less px

DP and PX Conversion formula:

Pixs =dips * (densitydpi/160).

Dips= (pixs*160)/densitydpi

How to convert the DP to PX:

PublicStaticIntDIP2PX (context context, float Dipvalue) {
Final float Scale=Context.getresources (). Getdisplaymetrics (). density;
Return (Int) (Dipvalue*Scale+0.5f);
}

PublicStaticIntPx2dip (context context, float Pxvalue) {
Final float Scale=  Context.getresource (). Getdisplaymetrics (). density;
return () (Pxvalue  scale 0} /span>


vga:640*480

qvga:320*240

hvga:320*480

wvga:800*480

wqvga:480x272 or 400x240

Resolution (number of levels x vertical number) type ratio 88x72 qqcif 11:9 128x96 sub-qcif 4:3 128x128 know to complement 1:1 160x120 QQVGA 4:3 176x144 QCIF 11:9 208x176 sub- Qvga-13:11 220x176 SUB-QVGA 5:4 240x176 sub-qvga+ 15:11 320x200 CGA 16:10QVGA 4:3 352x288 CIF 11:9 640x360 nHD 4:3 400x240 WQVGA 5:3 400x320 WQVGA 5:4 480x240 WQVGA 2:1 480x272 WQVGA 16:9 480x320 HQVGA 3:2 640x480 VGA 4:3 640x350 EGA 64:35 720x480 vga+ 3:2 768x576 PAL 800x480 WVGA 5:3 854x480 F WVGA 16:9 800x600 SVGA 4:3 960x540 QHD 16:9 960x640 DVGA 3:2 1024x600 WSVGA 128:75 1024x768 XGA 4:3 1280x768 WXGA 15:9 1280x800 WXGA 16:10 1280x960 uxga/xvga 4:3 1280x1024 SXGA 25:16 1400x1050 sxga+ 4:3 1440x900 wxga+ 16:10 1600x1024 WS XGA 25:16 1600x1050 WSXGA 32:21 1600x1200 usvga/uxga/uga 4:3 1680x1050 wsxga+ 16:10 1900x1200 UXGA 19:12 1920x1080 wsuvga+ (WSUGA/HDTV) 4:3 1920x1200 WUXGA 16:10 2048x1536 SUVGA (QXGA) 4:3 2560x1600 uwxga 16:10 2560x2048 USXGA 5:4 3200x2400 QUXGA 4:3 3840x2400 WQUXGA 16:10    

The unit of measurement for Android PX,IN,MM,PT,DP,DIP,SP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.