<span id="Label3"></p><p><p><strong>first,</strong> <strong>Overview</strong></p></p><p><p>We often set the length of the container in the layout of the page, but it is annoying to use which unit <strong>is</strong> the Length.</p></p><p><p>There are several types of description size areas that are supported in ANDROID.</p></p><p><p><strong>px</strong> (pixels)-- <strong>pixels</strong> : Different devices display the same effect, generally we HVGA represent 320x480 <strong>pixels</strong> , this use More.</p></p><p><p><strong>Dip</strong> (device Independent pixels)-- <strong>equipment independent pixels</strong> : This is related to device hardware, General OH we recommend this <strong>for</strong> support wcga, hvga, and qvga, and do not depend on <strong>pixels</strong> . Equivalent to Dp.</p></p><p><p>SP (scaled pixels-best for text size)--proportional <strong>pixels</strong> .</p></p><p><p>PT (points)--lb: 1pt = 1/72 inch</p></p><p><p>In (inches)--inch</p></p><p><p>MM (MILLIMETERS)-MM</p></p><p><p><strong>second,</strong> <strong>detailed</strong></p></p><p><p>SP because it is to enlarge the <strong>pixel</strong> , mainly for the font display, according to Google's recommendation, TextView font size is best used SP do units, and view the source of TextView know Android default level <strong>for use as</strong> Font size Units.</p></p><p><p>The most commonly used in Android is <strong>px</strong> and <strong>dip</strong>. But what is the difference between the two?</p></p><p><p>In the HVGA screen DENSITY=160;QVGA screen DENSITY=120;WVGA screen DENSITY=240;WQVGA screen density=120 density value represents the number of display points per inch, and the resolution is two Concepts. For different density screen resolution information, take the WVGA (density=240) of the 480<strong>dip</strong>*800<strong>dip</strong> <strong>as</strong> an example.</p></p><p><p>DENSITY=120 screen Actual resolution is *400<strong>px</strong> (two points <strong>for</strong> one resolution)<strong></strong><br>Status bar and title bar high each<strong>px</strong> or<strong>dip</strong><br>The horizontal screen is a screen width of<strong>px</strong> or a<strong>dip</strong>, the working area height 211<strong>px</strong> or 480<strong>dip</strong><br>Screen width up to<strong>px</strong> or 480<strong>dip</strong>, working area height 381<strong>px</strong> or 775<strong>dip</strong> , Vertical Screen</p></p><p><p>density=160 Screen Actual resolution <strong>is the</strong> *533<strong></strong><strong>px</strong> (3 points corresponding to two Resolution)<br>Status bar and title bar tall<strong>px</strong> or<strong>dip</strong><br>Horizontal screen is screen width 533<strong>px</strong> or<strong>dip</strong>, working area height 295<strong>px</strong> or 480<strong>dip</strong><br>Screen width when vertical screen is either<strong>px</strong> or 480<strong>dip</strong>, working area height 508<strong>px</strong> or 775<strong>dip</strong></p></p><p><p>density=240 Screen Actual resolution <strong>is</strong> 480<strong>px</strong>*800<strong>px</strong> (one point for one Resolution)<br>Status bar and title bar tall,<strong>px</strong> or<strong>dip</strong><br>The horizontal screen is a screen width of<strong>px</strong> or a<strong>dip</strong>, the working area height 442<strong>px</strong> or 480<strong>dip</strong><br>Screen width 480<strong>px</strong> or 480<strong>dip</strong>, working area height 762<strong>px</strong> or 775<strong>dip</strong> when Vertical Screen</p></p><p><p>APK resource bundle, When the screen density=240 use the hdpi tag resource<br>Resources that use MDPI tags when the screen is density=160<br>When the screen density=120, use the ldpi tag resource.<br>Resources that are not tagged are shared in a variety of resolution SCENARIOS.</p></p><p><p>**************************************************************************************************</p></p>Reference on Android<strong><strong>Dip</strong></strong>Dp<strong><strong>px</strong></strong>, SP and other units description<p><p>This article refers to the shixin20051108 "android on the <strong>dip</strong>, dp,<strong>px</strong>, SP and other unit description"</p></p><p><strong>[<strong><strong>Dip</strong></strong>: device independent pixels (<strong><strong>device independent pixels</strong></strong>). Different devices have different display effect, this and equipment hardware, generally we<strong><strong>to be</strong></strong>Support wvga, HVGA and QVGA recommend this, do not rely on<strong><strong>Pixel</strong></strong>。<br><strong><strong>px</strong></strong>: Pixels (<strong><strong>Pixel</strong></strong>). Different devices show the same effect, generally we HVGA represent 320x480<strong><strong>Pixel</strong></strong>, this is used More.<br>pt:point, is a standard length unit, 1pt=1/72 inches, for the printing industry, very simple to use;<br>sp:scaled Pixels (enlarge<strong><strong>Pixel</strong></strong>). Mainly used for font display of best for Textsize.<br>=========================<br>About Conversions (in SP and PT<strong><strong>to be</strong></strong>Cases<br>See TextView and other types of source code, you know:<br>Case Complex_unit_<strong><strong>PX</strong></strong>:<br>Return value;<br>Case Complex_unit_sp:<br>return value * metrics.scaleddensity;<br>Case Complex_unit_pt:<br>return value * metrics.xdpi * (1.0f/72);<br>--------------------------<br>scaleddensity = Density_device/(float) density_default;<br>xdpi = density_device;<br>--------------------------<br>Density_default = Density_medium = 160;<br>============================================<br>So: assuming the PT and SP take the same value of 1, you can set the coefficient between 1pt and 1SP<strong><strong>to be</strong></strong>X<br>1 * density_device/72 = x * 1 * density_device/160 =><br>x = 160/72 = 2.2222<br>That means that in Android, 1pt is about 2.22sp.<br>===================================================================<br>What is<strong><strong>Dip</strong></strong>and SP<br>In the past, programmers often<strong><strong>Pixel</strong></strong><strong><strong>to be</strong></strong>The Unit designs the computer user Interface. For example, define a width<strong><strong>to be</strong></strong>300<strong><strong>Pixel</strong></strong>form fields, spacing between columns<strong><strong>to be</strong></strong>5 x<strong><strong>Pixel</strong></strong>, Icon size<strong><strong>to be</strong></strong>16x16<strong><strong>Pixel</strong></strong>such as The problem with this approach is that if you run the program on a new monitor with a higher dots per inch (dpi), The user interface will appear Small. In some cases, the user interface may be too small to see the Content.<br>Resolution-independent units of measure can solve this problem. Android supports all of the following Units.<br><strong><strong>px</strong></strong>(<strong><strong>Pixel</strong></strong>): the point on the Screen.<br>In (inches): unit of Length.<br>MM (mm): Unit of Length.<br>PT (lb): 1/72 Inches.<br>DP (density-independent<strong><strong>Pixel</strong></strong>): an abstract unit based on screen Density. 1DP = 1 on the monitor at 160 dots per inch<strong><strong>px</strong></strong>。<br><strong><strong>Dip</strong></strong>: Same as dp, more for Android/ophone Example.<br>SP (scale-independent<strong><strong>Pixel</strong></strong>): similar to dp, but can be scaled based on the User's font size preference.<br><strong><strong>to be</strong></strong>The user interface to display the current and future display types, It is recommended that you always use SP as<strong><strong>to be</strong></strong>The text size of the unit that will<strong><strong>Dip</strong></strong>For<strong><strong>to be</strong></strong>The units of other Elements. of course, You can also consider using vector graphics instead of bitmaps</strong></p><p><strong><strong>*********************************************************************<br></strong></strong><strong><strong> <strong>Dip</strong>: device independent pixels ( <strong>unit independent pixels</strong> ).</strong></strong>Different devices have different display effect, this and equipment hardware, generally we<strong><strong>to be</strong></strong>Support wvga, HVGA and QVGA recommend this, do not rely on<strong><strong>Pixel</strong></strong>。<br><strong><strong> <strong>px</strong>: pixels ( <strong>pixels</strong> ).</strong></strong>Different devices show the same effect, generally we HVGA represent 320x480<strong><strong>Pixel</strong></strong>, this is used More.<br><strong><strong>Pt:point</strong></strong>, is a standard length unit, 1pt=1/72 inches, for the printing industry, very simple to use;<br><strong><strong>sp:scaled pixels (enlarge <strong>pixels</strong> ).</strong></strong>Mainly used for font display of best for Textsize. As a result, according to Google's advice, TextView's<br>The size of the best use SP to do units, and view TextView source know that Android by default using SP as<strong><strong>to be</strong></strong>Font size Units.<br>In Android, 1pt is probably equal to 2.22SP or more for reference if the UI is capable of using SP<strong><strong>to be</strong></strong>Units provide the best design, and if there is no concept of SP in the design, the developer can also take approximate values with appropriate conversions.<br>In the past, programmers often<strong><strong>Pixel</strong></strong><strong><strong>to be</strong></strong>The Unit designs the computer user Interface. For example, define a width<strong><strong>to be</strong></strong>300<strong><strong>Pixel</strong></strong>form fields, spacing between columns<strong><strong>to be</strong></strong>5 x<strong><strong>Pixel</strong></strong>, Icon size<strong><strong>to be</strong></strong>16x16<strong><strong>Pixel</strong></strong>such as The problem with this approach is that if you run the program on a new monitor with a higher dots per inch (dpi), The user interface will appear Small. In some cases, the user interface may be too small to see the Content.<br>Resolution-independent units of measure can solve this problem. Android supports all of the following Units.<br><strong><strong>px</strong></strong>(<strong><strong>Pixel</strong></strong>): the point on the Screen.<br>In (inches): unit of Length.<br>MM (mm): Unit of Length.<br>PT (lb): 1/72 Inches.<br>DP (density-independent<strong><strong>Pixel</strong></strong>): an abstract unit based on screen Density. 1DP = 1 on the monitor at 160 dots per inch<strong><strong>px</strong></strong>。<br><strong><strong>Dip</strong></strong>: Same as dp, more for Android/ophone Example.<br>SP (scale-independent<strong><strong>Pixel</strong></strong>): similar to dp, but can be scaled based on the User's font size preference.<br>Resolution: the whole screen is how many points, such as 800x480, it is for the software to display units, to<strong><strong>px</strong></strong><strong><strong>to be</strong></strong>The point of the Unit. The density (density) value represents the number of display points per inch, and the resolution is two Concepts. APK in the resource bundle,<br>Resources that use HDPI tags when the screen is density=240<br>Resources that use MDPI tags when the screen is density=160<br>When the screen density=120, use the ldpi tag resource.<br>General Android Set length and width multi-purpose<strong><strong>Dip</strong></strong>, set the font size to multi-use SP. On screen density<strong><strong>to be</strong></strong>160,1dp=1<strong><strong>px</strong></strong>=1<strong><strong>Dip</strong></strong>, 1pt = 160/72 sp 1pt = 1/72 Inches. when the screen density<strong><strong>to be</strong></strong>At 240, 1dp=1<strong><strong>Dip</strong></strong>=1.5<strong><strong>px</strong></strong>.<br><strong><strong>to be</strong></strong>The user interface to display the current and future display types, It is recommended that you always use SP as<strong><strong>to be</strong></strong>The text size of the unit that will<strong><strong>Dip</strong></strong>For<strong><strong>to be</strong></strong>The units of other Elements. of course, You can also consider using vector graphics instead of bitmaps.</p><p><p>31.Android Common units px, dip, SP Learning</p></p></span>
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