Differences between px, dp, dip, and sp in Android

Source: Internet
Author: User

Differences between px, dp, dip, and sp in Android
Recently I have been studying Android development and have not figured out the differences among px, dp, dip, and sp. Today we have time to study it. As we all know, there are a lot of Android manufacturers, and there are endless Android phones and tablets of various sizes. As a result, the fragmentation of the Android ecosystem becomes more and more serious. Google defines px, dp, dip, and sp in the Android development documentation to help developers adapt to Android devices with different resolutions. 1. Basic Knowledge: mm: millimeters mm, length unit. In: inches inch, length unit, basic unit of physical screen size. Pt: a standard unit of points. The size is 1 inch of the screen size of 1/72. Dpi: dots per inch is the pixel per inch. For example, if the physical size of the QVGA (320*240) resolution screen is (2 inch * 1.5 inch), the dpi of the mobile phone is 160. Screen size refers to the actual physical size of the mobile phone. For example, if iPhone4S is 3.5 inch, the diagonal line of the mobile phone screen is 3.5 inch. Resolution refers to the number of pixels in the horizontal and vertical directions of the mobile phone screen. Common mobile phone resolutions: QVGA (240x320 pixels), HVGA (480x320 pixels), WVGA (800x480 pixels), 720 P (x pixels ), 1080 P (1920x1080 pixels), 2 K (2560x1440 pixels) 2. basic definition: px (Pixel) refers to a Pixel. Sp (scale-independent pixels) is a proportional independent pixel. Dip (device independent pixels) is a device independent pixel. Dp :( Density-independent pixel) in the Android document (http://developer.android.com/guide/practices/screens_support.html#terms), it is calculated as: px = dp * (dpi/160 ). Let's take a look at what the unit of dp is: pixel = the unit of dp * pixel/inch. We can see that the unit of dp is the length unit. 1dp length = 1 * dpi/160*1/dpi inches = 1/160 inch. The significance of dp is: you can set the corresponding dp value in the application based on the actual size, so that different devices look as big. 3. the difference is that pixel (pixel) represents the real pixels of the screen. For example, for popular 1080 p mobile phones and 2 k mobile phones, P mobile phones are X pixels, that is, the screen of this mobile phone has pixels horizontally, the portrait is 1920 pixels. This value is absolute, and it will not change. Sp (proportional independent pixel), that is, pixels irrelevant to the density and font zoom, mainly used for the font size. Dip (device independent pixel) is a logical pixel unit, which is actually a dp.

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.