Android Basics px, DP, SP understanding

Source: Internet
Author: User

PX is pixels (pixels), all kinds of cell phone pixels are different, 1px is to represent a mobile phone screen a physical pixel point. The resolution of a screen is 240*320, so the screen is 240 pixels wide and the screen is 320 pixels high. If the screen size is not changed and the resolution is increased, then the corresponding width and height of the pixels will become more, so that the picture looks clearer and more delicate.

DP is the abbreviation for Dip,device independent pixels (device-independent pixels), which used to use dips, and later recommended DP form for uniform styling. The display of the DP-unit is related to the pixel density dpi (dots perinch) of the screen, and the pixel density is the number of pixels in a pixel, such as 1.5*2 inch screen, 240*320 resolution, then 240/1.5= 160DPI is the horizontal pixel density, 320/2=160dpi is the vertical pixel density.

As can be seen from the PX and DP is not the same, PX units when the physical size of the display on different screens may be different, and PD units when the physical size displayed on different screens is basically the same, see the following analysis to know the difference between PX and DP.


(where the actual length = screen length/pixel value of the total pixel px * setting in that direction)

For example: 100*100px picture in 1.5*2 inch screen, 240*320 resolution display effect physical size for

Width: 1.5/240*100 = 0.625 inch

Height: 2/320*100 = 0.625 inch

The actual size of the picture is 0.625*0.625 inches.


100*100px picture in 1.5*2 inch screen, 480*800 resolution display effect physical size for

Width: 1.5/480*100 = 0.3125 inch

Height: 2/800*100 = 0.3125 inch

The actual size of the picture is 0.3125*0.3125 inches.


(where 160pdi is the standard, i.e. 160pdi, 1px = 1PD;

Pixel density PDI = One Direction total pixels px/screen that direction length;

Pixel px = pixel density pdi/160 * Independent pixel PD set)

For example: 100*100PD picture in 1.5*2 inch screen, 240*320 resolution display effect physical size for

Width: 240/1.5 = 160pdi

160/160*100 = 100px

1.5/240*100 = 0.625 inch

Height: 320/2 = PDI

160/160*100 = 100px

2/320*100 = 0.625 inch

The actual size of the picture is 0.625*0.625 inches.


100*100PD picture in 1.5*2 inch screen, 480*800 resolution display effect physical size for
Width: 480/1.5 = PDI

320/160*100 = 200px

1.5/480*200 = 0.625 inch

Height: 800/2 = PDI

400/160*100 = 250px

2/800*250 = 0.625 inch

The actual size of the picture is 0.625*0.625 inches.

One can see the effect of PX as a unit, the same picture, placed on the same size of the screen phone, because the resolution is different, but the size is different, this is not very much in line with our needs? To solve this problem we introduced the use of PD as the unit. From the above can also be seen as a unit of PD effect, the same picture, placed on the same size of the screen phone, although the screen resolution is different, but the actual size of the display is the same, in line with our design requirements.

The SP is a font-size unit, similar in principle to DP.


PX, DP, SP, dip, dpi noun explanations refer to the following

Http://www.cnblogs.com/wader2011/archive/2011/11/29/2267490.html

This article is from the "Remember" blog, be sure to keep this source http://ziruo.blog.51cto.com/10107518/1653999

Android Basics px, DP, SP understanding

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.