Size measurement units (px, DPI, DP, dip, SP) for Android app Development view

Source: Internet
Author: User

Http://blog.csdn.net/ljianhui/article/details/43601495?ref=myread

One, pixel (px) and screen resolution

1)px (Pixels, pixels): corresponds to the actual pixel point on the screen. For example, the 320*480 screen has 320 pixels in the landscape and 480 pixels in the portrait.

2) The screen resolution is the sum of the physical pixels displayed on the screen, which equals the pixels on the width of the screen on pixels * height. On the development of Android applications, the screen resolution is not used.

3) The screen resolution is wide * high, but it has no relation to the size of the screen, it is related to the number of pixels on a screen.

Second, DPI

1) dpi: pixels per inch, is the unit of screen pixel (px) density. Pixel density is the number of pixels that the screen specifies to be displayed within the physical wide range.

2) in Android , DPI has the following categories, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi

3) in reality, Mdpi square inches. Ldpi,hdpi,xhdpi< Span lang= "ZH-CN" is 320dpi,xxhdpi,xxxhdpi,hdpi The density of ,xhdpi,xxdpi ,xxxhdpi

4) DPI is independent of the size of the screen, which is just a measure of the pixel density.

Third, DP

Independent of the physical density of the unit of measurement, it is based on 160dpi , regardless of the DPI screen, 1DP represents the same physical length. In the 160dpi screen, 1DP=1px, that is, a DP needs to be represented by an PX , on the 240dpi screen, 1DP=1.5px, indicating a DP needs 1.5 px to indicate. That is to say 1DP=dpi/160*px. The implication is that developers will be able to develop a UI that displays the same size, regardless of the DPI screen. That is, in the same size, but different resolution of the phone, with the DP logo, the size of the display is the same.

Four, dip

Same as DP , except the name is not the same.

Five, SP

Scaled pixels The abbreviation of the magnified pixel, specifically for handling the font size. It is not only related to screen dpi, but also to the system's default font size. For the same SP value, the higher the screen dpi, the smaller the font is displayed, and the larger the system font, the larger the font is displayed. That's why all the fonts that use the SP have changed since we set the system font size.

If the font is in DP, the system font size is changed, and the font size of the interface's view does not change.

For example: for the following code, two TextView in a vertically distributed linearlayout, the first TextView uses the SP as the unit of the font, and the second TextView uses the unit of the DP as the font:

[HTML]View PlainCopy print?
  1. <span style="Font-family:microsoft yahei;font-size:18px;" ><TextView
  2. android:text="@string/hello_world"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:textsize="28sp" />
  6. <TextView
  7. android:text="@string/hello_world"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:textsize="28DP" />
  11. </span>

Under the MDPI device, the system font is the hour, as follows:


The fonts are the same size in both ways. On hdpi devices, when the system font is normal, its effect is the same.

When I set the font to extra large, the effect is as follows:

You can see that the size of the font using the DP has not changed, and the font used by the SP has become significantly larger.

Size measurement units (px, DPI, DP, dip, SP) for Android app Development view

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.