Dip px: display unit px and dip and SP differences

Source: Internet
Author: User
Tags return

Dip:device independent pixels (device independent pixel). Different devices have different display effects, this is related to the device hardware, we generally support WVGA, HVGA and QVGA CWJ recommended Use this, do not rely on pixels.
Px:pixels (Pixel). Different devices display the same effect, generally we hvga represent 320x480 pixels, this use more.
Pt:point, is a standard length unit, 1pt=1/72 inches, used in the printing industry, is very simple and easy to use;
sp:scaled pixels (zoom in pixels). Mainly used for font display best for textsize.
Thus, according to Google's proposal, TextView's font size is best to use SP to do units, and view
TextView
The source code that Android uses the SP as the default font size unit.
###################################################################
About conversions (Take SP and PT for example)
See TextView and other types of source code, know:
Case COMPLEX_UNIT_PX:
return value;
Case COMPLEX_UNIT_SP:
return value * metrics.scaleddensity;
Case COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0F/72);
--------------------------
Scaleddensity = Density_device/(float) density_default;
xdpi = Density_device;
--------------------------
Density_default = Density_medium = 160;
============================================
So: If the PT and SP take the same value of 1, you can set the coefficient of x between 1pt and 1SP,
1 * density_device/72 = x * 1 * density_device/160 =>
x = 160/72 = 2.2222
Which means that in Android, 1pt is about 2.22SP.
For reference, if the UI can provide the design in the SP as the best, if the design does not have an SP
, developers can also use the appropriate conversions to get an approximate value.

This article links http://www.cxybl.com/html/wyzz/CSS/20120614/30134.html

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.