Measurement Units supported by Android

Source: Internet
Author: User

The link cannot be provided because the link on the android official website is harmonious. The following content is displayed in the cache of Google Android in Japanese. Save it.

1. you can create common dimensions to use for various screen elements by defining dimension values in XML. A dimension resource is a number followed by a unit of measurement. for example: 10px, 2in, 5sp. here are the units of measurement supported by Android:

(1) Px --> pixels-corresponds to actual pixels on the screen.

(2) In --> inches-based on the physical size of the screen.

(3) Mm --> millimeters-based on the physical size of the screen.

(4) Pt --> points-1/72 of an inch based on the physical size of the screen.

(5) DP --> density-independent pixels-an abstract unit that is based on the physical density of the screen. these units are relative to a 160 DPI screen, so one DP is one pixel on a 160 DPI screen. the ratio of DP-to-pixel will change with the screen density, but not necessarily in direct proportion. note: The Compiler accepts both "dip" and "DP", though "DP" is more consistent with "SP ".

(6) sp --> Scale-independent pixels-this is like the DP unit, but it is also scaled by the user's font size preference. it is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

2. dimension values are not normally used as raw resources, but rather as attribute values in XML files. You can, however, create plain resources containing this data type.

Source File Format: XML file requiring a declaration, and a root  Element containing one or more  Tags.

Resource source file location: Res/values/dimens. XML (file name is arbitrary; standard practice is to put all dimensions in one file already Ted to dimensions .)

Compiled resource datatype: Resource pointer to a dimension.

Resource reference Name:

Java: R. dimen. some_name

XML: @ [Package:] dimen/some_name (where some_name is the name of a specific  Element)

Syntax

XMLCode

< Dimen   Name = Dimen_name > Dimen_value </ Dimen >  

<Dimen> A valid dimension value. name-the name used in referring to this dimension.

Example XML Declaration

The following Code declares several dimension values.

  • < Dimen   Name = "Double_density" > 2dp </ Dimen >
  • < Dimen   Name = "Sixteen_sp" > 16sp </ Dimen >
  • </Resources>
  •  

    Example Java code:

    Java code

    Float dimen = resources. getdimen (R. dimen. one_pixel );

    Example XML code:

    XML Code

  • textview Android: layout_width = " fill_parent "
  • Android: layout_height = " wrap_content "
  • Android: textsize="@ Dimen/sixteen_sp"/> 
  •  

    3. Summary

    Dip: Device Independent pixels (device independent pixel). Different devices have different display effects.

    Px: pixels (pixels). Different devices have the same display effect.

    SP: scaled pixels (zoom in pixels). It is mainly used to display the best for textsize in fonts.

    Pt/In/mm is not explained. There is nothing to explain.

     

    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.