Length units in Android px, DP, SP

Source: Internet
Author: User

1.px

This is not much of an explanation, it is a physical pixel point on the screen. Eyes good small partner carefully look at the screen should be able to see the small lattice, not a drop of water to see.

It is not recommended to use PX, the same picture may be different on different phone sizes. High resolution display of the small, low resolution of the large display.

2.dp

This unit should be carefully understood, and it is related to pixel density. First say pixel density dpi, which is the number of pixels per inch. If my phone screen size is 1.5 inches x2 inches and the resolution is 240x320, then its pixel density is 160dpi.

The Android system defines 4 resolutions: Low (120DPI), Medium (160DPI), High (240dpi), Ultra High (320DPI), and the corresponding DP-to-PX conversion coefficients are 0.75, 1, 1.5, 2, which multiply by DP length is the number of pixels. If my cell phone pixel density is 240dpi, now there is a picture of 80dp in length, then the pixel length shown is 80x1.5=120px. If my other cell phone pixel density is 320dpi, then the actual pixel length is 160px. In this way, the same pictures on the different phones display the size of almost no difference.

3.dip

Density independent pixels, device independent pixels.

Exactly the same as DP, with different names, no more explanations.

4.sp

Abstract pixels independent of scale (Scale-independent Pixel).

and DP very similar but the only difference is that the Android system allows users to customize the text size (small, normal, large, oversized, etc.), when the text is normal large hours 1SP=1DP, other sizes larger than 1DP or smaller.

Recommendation: text with SP units, other non-text with DP units . For example textsize= "16sp", layout_width= "60DP", occasionally also need to use PX units, such as drawing a split line.

Length units in Android px, DP, SP

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.