Differences between PX, dip, and SP in Android

Source: Internet
Author: User

I. Overview

We often set the container length during page layout, but we are annoyed by which unit of length should be used.

The following types of description areas are supported in Android.

Px (pixels)-pixels: different devices have the same display effect. Generally, hvga represents 320x480 pixels, which is usually used.

Dip (device independent pixels) -- device independent pixel: This is related to the device hardware. Generally, we recommend that you use this parameter to support wcga, hvga, and qvga, instead of pixels. Equivalent to DP.

SP (scaled pixels-best for text size) -- pixels with proportions.

Pt (points) -- LB: 1pt = 1/72 inch

In (INCHES) -- inch

Mm (millimeters) -- Mm

Ii. Details

SP because it is a magnified pixel, it is mainly used for font display. According to Google's suggestion, it is best to use SP as the unit for textview font size, the source code of textview shows that android uses the horizontal font size unit by default.

Px and dip are the most commonly used in Android. But what is the difference between the two?

In the hvga screen density = 160; qvga screen density = 120; WVGA screen density = 240; wqvga screen density = 120
The value of density indicates the number of display points per inch, and resolution. For the screen resolution information of different density
For example, WVGA (density = 240.

 

Density = 120
The actual screen resolution is 240px * 400px.
(Two vertices correspond to one resolution)
The height of the status bar is 19px or 25dip.
The screen width is 400px
Or 800dip, working area height 211px or 480dip
Screen width: Px or dip, working area Height: 381px or 775dip

 

Density = 160
The actual screen resolution is 320px * 533px.
(Three points correspond to two resolutions)
The height of the status bar is 25px or 25dip.
The screen width is 533px.
Or 800dip, working area height 295px or 480dip
Screen width: 320px or 480dip, working area Height: 508px or 775dip

 

Density = 240
The actual screen resolution is 480px * 800px.
(One point for one resolution)
The height of the status bar and title bar is 38px or 25dip.
The screen width is 800px
Or 800dip, working area height 442px or 480dip
Screen width 480px or 480dip, working area height 762px or 775dip

 

 


In the APK resource package, hdpi is used when the screen density is 240
Tag Resources
Resources that use the mdpi label when the screen density is 160
Ldpi tag resources are used when the screen density is 120.
Resources without any tags are shared in various resolutions.

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.