Android screen density (Density) and resolution concept detailed

Source: Internet
Author: User
Tags comparison table

Mobile devices are big and small, so how to adapt to different screens, which has caused us programmers a lot of confusion. I also suddenly think of these issues, and then go online search related things, organized as follows. First, you must understand the following length units. Length units in Android (DP, SP, PX, in, PT, mm) see a lot of netizens do not understand the difference between DP, SP and PX: Now introduce the DP and SP. DP is also dip. This is basically similar to SP. You can use a DP or SP if you set properties that represent length, height, and so on. However, if you set the font, you need to use the SP. The DP is not density-independent, and the SP is not related to scale, except for density. If the screen density is 160, then the DP and SP and PX are the same. 1DP=1SP=1PX, but if you use PX as the unit, if the screen size is constant (assuming 3.2 inches), the screen density becomes 320. So the original width of the TextView is set to 160px, in the density of 320 of the 3.2-inch screen is more than the density of 160 of the 3.2-inch screen to see the half-short. But if it is set to 160DP or 160SP. The Width property value is automatically set to 320px. That means 160 * 320/160. 320/160 of these are called density scale factors. That is, if you use the DP and SP, the system will automatically convert based on the change in screen density. Let's see what other units mean. PX: (pixels) (pixels): dots on the screen, related to density. The density is large, the PX on the unit area will be more. Represents the actual pixel of the screen. For example, the 320*480 screen has 320 pixels in the landscape and 480 pixels in the portrait. Dip or DP (density-independent pixels). This is related to device hardware, which is recommended in order to support WVGA, HVGA, and QVGA 5 of the binary space. An abstract unit based on screen density. Set some view of the width of the high can use this, in general, at different resolutions, will not have the feeling of zooming. If using PX, 320px is full of HVGA width, to the WVGA can only account for half of the screen, that must not be what you want.
SP (scale independent pixels) enlarges pixels – primarily handles the size of the font.
In: represents inches, which is the physical size of the screen. Equal to 2.54 centimeters per inch. For example, describe the size of a mobile phone screen, often said, 3.2 (English), 3.5 (English), 4 (English) inch refers to this unit. These dimensions are the diagonal length of the screen. If the phone's screen is 3.2 inches, the diagonal length of the phone's screen (viewable area) is 3.2*2.54 = 8.128 centimeters. Readers can measure their own phone screen to see if the actual size is the same.
MM: Represents the millimeter, which is the physical size of the screen.
PT: Represents a point, which is a physical length of the screen with a size of 1 inches of 1/72. Conversion formula: px = (density/160) DP
Density is typically 3 common fixed values 240/160/120
corresponding WVGA/HVGA/QVGA respectively
Do not know the resolution of the confidant to do the corresponding density is how many can click on the AVD Manager to create a new simulator or select the existing simulator point details can be seen (1.6 or more of the 1.6 can be checked)
Add: DP and dip is the same, but PX and DP (DIP) is absolutely different, the only case is the same as the HVGA resolution, because the HVGA resolution corresponds to density 160, and divisor, so do not feel the difference next, When we create an emulator, there is an option to choose the size of the simulator, in fact, the selection of the simulator screen size, is what we often say the resolution. such as: 320*48 and so on. Density means "density". Density, meaning the size of the capacity within the unit area. HVGA Screen density=160
QVGA screen density=120
WVGA screen density=240
The WQVGA screen density=120 density value represents the number of display points per inch, and the resolution is two concepts. Screen resolution information for different density: 480*800 WVGA (density=240)
DENSITY=120 screen Actual resolution is 240*400 (two points corresponds to a resolution)

Screen width 400px or 800dip, working area height 211px or 480dip
Screen width 240px or 480dip when vertical screen, working area height 381px or 775dip
DENSITY=160 screen Actual resolution is 320px*533px (3 points corresponds to two resolution)
Status bar and title bar tall 25px or 25dip
Screen width 533px or 800dip, working area height 295px or 480dip
Screen width 320px or 480dip when vertical screen, working area height 508px or 775dip

density=240 screen Actual resolution is 480px*800px (one point for one resolution)
Status bar and title bar tall 38px or 25dip
Screen width 800px or 800dip, working area height 442px or 480dip
Screen width 480px or 480dip when vertical screen, working area height 762px or 775dip

APK resource Bundle, when the screen density=240 use the hdpi tag resource
Resources that use MDPI tags when the screen is density=160
When the screen density=120, use the ldpi tag resource.
Resources that are not tagged are shared in a variety of resolution scenarios.
Use unit dip as much as possible in layout, use less px
Screen width height dimension size density

Type (Pixels) (Pixels) Range (inches) Size Group

QVGA 2.6-3.0 Small Low
WQVGA 3.2-3.5 Normal Low
FWQVGA 432 3.5-3.8 Normal Low
HVGA 480 3.0-3.5 Normal Medium
WVGA 480 3.3-4.0 Normal High
FWVGA 480 854 3.5-4.0 Normal High
WVGA 480 4.8-5.5 Large Medium
FWVGA 480 854 5.0-5.8 Large Medium

Screen size and density comparison table: <ignore_js_op> The following is a way to set whether the app supports multi-density at different resolutions in manifest.
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android" >
...
<supports-screens
Android:smallscreens= "true"
Android:normalscreens= "true"
Android:largescreens= "true"
Android:xlargescreens= "true"
Android:anydensity= "true"/>
</manifest> <ignore_js_op> 3 , scaling of bitmap resourcesWhen scaling a bitmap resource, take full account of the device's height and width, and get the device's height and width code as it runs:
1 2 3 4 WindowManager mwmgrmwmgr = (windowmanager) context.getsystemservice (context.window_service); int width = Mwmgr.getdefaultdisplay (). getwidth (); int Height–mwmgr.getdefaultdisplay (). GetHeight ();
Here are some highly recommended recommendations:
    • In the XML layout, use Wrap_content and fill_parent to populate the entire parent window;

    • Use Framelayout, rather than absolutelayout, to reduce the screen size dependence of the interface layout;

    • Never use hard-coding for pixel value, the use Dip (density independent pixel);

    • Prepare the right picture resources for different devices according to density and resolution.

Android screen density (Density) and resolution concept detailed

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.