A brief analysis of the difference between Px,dp,dip and SP in Android

Source: Internet
Author: User

PX is a pixel width-independent pixel (device), device independent pixel (DIP) is the font size of the device you want to use, and device independent pixel for all things. Here the device independent pixel--

Dphttp://developer.android.com/guide/topics/resources/more-resources.html#dimension

Px, pixel-equivalent to the actual pixel on the screen.

In, inch-based on the physical dimensions of the screen

m--MM-based on the physical dimensions of the screen

Pt, Dot--based on the physical dimensions of the screen, one of 72 points in inches

Dp, density-independent pixel-an abstract unit based on the physical density of the screen. This unit is proportional to the 160-resolution screen, so in a 160-resolution screen, 1DP is 1px. The ratio of DP to pixel will change as the density of the screen changes, but it is not necessarily proportional. Note: The compiler accepts both "Dip" and "DP", although DP is more compliant than SP.

Sp, scale-independent pixels-it's like a DP unit, but it also depends on the font size of the user's preference. When specifying the font size, I recommend that you use this unit because it adjusts both the density of the screen and the user's preferences.


Summary: Use a DP for anything other than a font, using the SP for the font. For various screens of different sizes and densities, almost everything about this and how to achieve the best support. For more than one type of device, if you have any serious problems developing an Android app, you should read the top content at least once. In addition, it is important to know the number of active users for a particular screen device.

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.