Android measurement unit

Source: Internet
Author: User

Historically, programmers always designed computer interfaces in
Terms of pixels. For example, you mightmake a field 300 pixels wide,
Allow 5 pixels of spacing between columns, and define icons 16-by-16
Pixels in size. The problem is that if you run that program on new
Displays with more and more dots per inch (DPI), the user interface
Appears smaller and smaller. At some point, it becomes too hard to read.
Resolution-independent measurements help solve this problem.
Android supports all the following units:
• PX (pixels): dots on the screen.
• In (INCHES): size as measured by a ruler.
• Mm (millimeters): size as measured by a rters.
• Pt (points): 1/72 of an inch.

DP (density-independent pixels): An abstract unit based on the density
Of the screen. On a display with 160 dots per inch, 1dp = 1px.
• Dip: synonym for DP, used more often in Google examples.
• Sp (scale-independent pixels): similar to DP but also scaled by the user's font size preference.
To
Make your interface scalable to any current and future type of display,
I recommend you always use the SP unit for text sizes and the dip Unit
For everything else. You shoshould also consider using vector graphics
Instead of bitmaps

If you do not want to read English, see the following:

Px: The pixel of the screen.

In: inches

MM: mm

PT: LB, 1/72 inch

DP: an abstract unit based on density. If a screen of DPI is displayed, 1dp = 1px.

Dip: equivalent to DP

SP: similar to DP, but it also scales according to the user's font size preference.

We recommend that you use SP as the unit of text, and dip for others.

The following is an overview of the relationship between DIP and PX:

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 details about the screen resolution of different density, take the WVGA (density = 240) of 480dip * 800dip as an example.

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

When 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, and the working area height is 295px or 480dip.
Screen width: 320px or 480dip, working area Height: 508px or 775dip

When 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 PX or dip, and the working area height is PX or dip.
Screen width 480px or 480dip, working area height 762px or 775dip

In the APK resource package, when the screen density is 240, the resources using the hdpi label
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.
Use the unit dip as much as possible during layout, and use less PX

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/hustpzb/archive/2010/11/20/6023145.aspx

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.