(ext.) DP and dip are the same unit

Source: Internet
Author: User

Original address: http://blog.csdn.net/chenyufei1013/article/details/8363619

    • Summary

This article introduces the concept of Android unit Dp,dip, and gives its exact meaning.

    • Overview

In Android, DP is density-independent Pixels shorthand, while dip is density independent Pixels, actually refers to a concept, are Android units. There are descriptions in the document more Resource types:

Dp
Density-independent Pixels-an Abstract unit that's based on the physical Density of the screen. These units is relative to a (dots per inch) screens, on which 1DP was roughly equal to 1px. When running on a higher density screens, the number of pixels used to draw 1dp are scaled up by a factor appropriate for th E Screen ' s dpi. Likewise, when on a lower density screens, the number of pixels used for 1DP was scaled down. The ratio of dp-to-pixel would change with the screen density, but not necessarily in direct proportion. Using DP units (instead of PX units) is a simple solution to making the view dimensions in your layout resize properly for Different screen densities. In other words, it provides consistency for the real-world sizes of your UI elements across different devices.

The unit PX represents the pixel, and the conversion formula for the DS is also described in document supporting multiple screens:

density-independent Pixel (DP)
A Virtual pixel unit, should use if defining UI layout, to express layout dimensions or position I n a density-independent.
the density-independent pixel is equivalent to one physical pixel on a (DPI screen), which is the baseline Density assumed by the system for a "medium" density screens. At runtime, the system transparently handles any scaling of the DP units, as necessary, based on the actual density of the Screen on use. The conversion of DP units to screens pixels is SIMPLE:PX = DP * (dpi/160). For example, on a-DPI screen, 1 DP equals 1.5 physical pixels. Should always use DP units when defining your application ' s UI, to ensure proper display of your UI on screens with Di Fferent densities.

Formula

[CPP]View Plaincopy
    1. PX = DP * (dpi/160)


Explain how many px the 1DP represents, and let's simply deduce the formula below.

First, the DPI is the abbreviation for dots Per inch (wiki), which indicates how many dots are in an inch, and for the UI interface, this point is pixel (Pixel).

Then, let's look at the DP units:

[Plain]View Plaincopy
    1. pixels = DP Units * pixels per inch


It can be seen that the unit of DP is the unit of length in inches, and the last sentence of the definition of DP above illustrates this: in other words, it provides consistency for the real-world sizes of your UI elements Across different devices.

Finally, let's look at how big the 1DP value is. 1DP corresponds to dpi/160 pixels, according to the definition of dpi, each pixel length is 1/dpi inches, together is 1dp=1/160 inch.

[CPP]View Plaincopy
    1. Length of 1DP = 1 * dpi/160 * 1/dpi "= 1/160"

    • Conclusion

DP equates to dip, which is a unit of length, 1dp=1/160 inches.

The meaning of the DP unit is that you can set the corresponding DP value in the app based on the actual size you see, making it look as large on different devices.

(ext.) DP and dip are the same unit

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.