Android screen measuring unit details, android measuring unit

Source: Internet
Author: User

Android screen measuring unit details, android measuring unit

1. px (pixels): it is the physical pixel of the screen, which is related to the density. The density is high and there will be more pixels per unit area. This is generally not recommended.

2. dip or dp (density-independent pixels): An abstract unit based on density. This is related to the hardware of the device. We recommend that you set the width and height of some views during development, in general, there is no sense of scaling at different resolutions. At runtime, Android transparently scales any required dip units based on the actual screen density in use.
3. sp (pixels unrelated to the scale): similar to dip/dp, sp scales based on the user's font size preferences, mainly used to set the font size.

Many of my friends may not be very clear about the difference between dip and px, including the differences I have not yet figured out. The following is a brief discussion:
First, make it clear:

HVGA screen density = 160; QVGA screen density = 120; WVGA screen density = 240; WQVGA screen density = 120

  

The value of density indicates the number of display points per inch, and resolution.

Conversion Formula from dip to px: px = dip * (density/160)

Android officially defines that dip is equivalent to a physical pixel on the 160dpi screen, that is, 1dip = 1px. For example, on a 240 dpi screen, 1dip equals 1.5px.

 

For the screen resolution information of different density values, take the WVGA (density = 240) of 480dip * 800dip as an example:
1. When density = 120, the actual screen resolution is 240px * 400px (two points correspond to one resolution). the status bar and title bar height are 19px or 25dip.
The screen width is 400px or 800dip, and the working area height is 211px or 455dip;
The screen width is PX or dip, and the working area height is 381px or 775dip.
2. When density = 160, the actual screen resolution is 320px * 533px (three points correspond to two resolutions). the status bar and title bar height are 25px or 25dip.
The screen width is 533px or 800dip, and the working area height is 295px or 455dip;
The screen width is 320px or 480dip, and the working area height is 508px or 775dip.
3. When density = 240, the actual screen resolution is 480px * 800px (one point for one resolution). the status bar and title bar height are 38px or 25dip.
The screen width is 800px or 800dip, and the working area height is 442px or 455dip;
Screen width: Px or dip, working area Height: Px or 775dip.

In the Android Application Package apk, the system will reference the corresponding resource file according to the specific situation of each device (Note: resources without any tags are shared in various resolutions ):

Resources that use the hdpi label when the screen density is 240;
Resources that use the mdpi label when the screen density is 160;
Ldpi tag resources are used when the screen density is 120.

In manifest, the following shows whether the app supports the multi-density method at different resolutions.

...<supports-screens     android:smallScreens="true"     android:normalScreens="true"     android:largeScreens="true"     android:xlargeScreens="true"     android:anyDensity="true" />... 

  

 

Appendix:
The system classifies the screen size and density as follows:

 

 

Table 1. The screen size and density of the simulator skin contained in the Android SDK, as well as other typical resolutions.

 

  Lowdensity (120), ldpi Medium density (1, 160), mdpi High density (240), hdpi Extra high density (320), xhdpi
Small screen QVGA (240x320)   480x640  
Normal screen WQVGA400 (240x400)
WQVGA432 (240x432)
HVGA (320x480) WVGA800 (480x800)
WVGA854 (480x854)
600x1024
640x960
Large screen WVGA800 ** (480x800)
WVGA854 ** (480x854)
WVGA800 * (480x800)
WVGA854 * (480x854)
600x1024
   
Extra Large screen 1024x600 WXGA (1280x800) elapsed )†
1024x768
1280x768
1536x1152
1920x1152
1920x1200
2048x1536
2560x1536
2560x1600

 

* To simulate this configuration, use WVGA800 or WVGA854 to create an AVD with a custom density of 160.
** To simulate this configuration, use WVGA800 or WVGA854 to create an AVD with a custom density of 120.

Auxiliary Tools:

import android.content.Context;  public class DensityUtil {        public static int dip2px(Context context, float dipValue) {          final float scale = context.getResources().getDisplayMetrics().density;          return (int) (dipValue * scale + 0.5f);      }      public static int px2dip(Context context, float pxValue) {          final float scale = context.getResources().getDisplayMetrics().density;          return (int) (pxValue / scale + 0.5f);      }  } 

  

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.