Article 3. Pre-development knowledge supplement: length units and screen resolutions of Android, which are also reproduced ~~, Android screen resolution

Source: Internet
Author: User

Article 3. Pre-development knowledge supplement: length units and screen resolutions of Android, which are also reproduced ~~, Android screen resolution
This article is a bit early, but it is very practical. For more information about the Unit, see the red part.

Screen Resolution Basics

1. terms and concepts

Terms

Description

Remarks

Screen size)

It refers to the actual physical size of the mobile phone, such as the commonly used 2.8 inch, 3.2 inch, 3.5 inch, 3.7 inch

Motorola's milestone mobile phone is 3.7 inch

Aspect Ratio (width/height Ratio)

Refers to the actual physical size width/height ratio, divided into long and nolong

Milestone is and belongs to long

Resolution (Resolution)

Similar to the definition of computer resolution, it refers to the number of pixels in the portrait and horizontal directions of the mobile phone screen.

Milestone is 854*480

DPI (dot per inch)

Number of pixels per inch, such as 120 dpi and 320 dpi. Assume that the physical size of the QVGA (240*2 inch) resolution screen is (1.5 inch * 160), dpi =

Can reflect the definition of the screen, used to scale the UI

Density (Density)

The pixel value concentration in the Screen. resolution/Screen size can reflect the cell phone density,

 

Density-independent pixel (dip)

The Unit for calculating the logic density. The formula for the dip and the specific pixel value is dip/pixel = dpi/160, that is, px = dp * (dpi/160)

 

 

2. DPI Value Calculation

For example, calculate the WVGA (800*480) Resolution, 3.7 inch density DPI, as shown in 1

 

Figure 1

Diagonal pixel indicates the pixel value of the Diagonal line (=), DPI = 933/3. 7 = 252

 

3. Mobile phone screen Classification

 

3.1 is divided into the following three categories based on the cell phone screen density (DPI) or screen size, as shown in figure 2.

 

Figure 2

3. 2 The relationship between mobile phone screen classification and pixel density is shown in Table 1:

 

Lowdensity (120), ldpi

Medium density (1, 160), mdpi

High density (240), hdpi

Small screen

QVGA (240x320)

 

 

Normal screen

WQVGA400 (240x400) WQVGA432 (240x432)

HVGA (320x480)

WVGA800 (480x800) WVGA854 (480x854)

Large screen

 

WVGA800 * (480x800) WVGA854 * (480x854)

 

Table 1

3.3 mobile phone size distribution (http://developer.android.com/resources/dashboard/screens.html) 3 shows, the current is mainly to the resolution of 800*480 and 854*480 mobile phone users mostly

 

 

Figure 3

From the above screen size distribution, we can only consider mobile phones with a density of 1 and 1.5 between 3-inches.

4. uidesign

From the perspective of development, the application provides three sets of UI layout files based on the screen of three types of Android phones, but three sets of corresponding interface icons are also required, as shown in table 2.

Icon Type

Standard Asset Sizes (in Pixels), for Generalized Screen Densities

 

Low density screen (ldpi)

Medium density screen (mdpi)

High density screen (hdpi)

Launcher

36x36 px

48x48 px

72x72 px

Menu

36x36 px

48x48 px

72x72 px

Status Bar

24x24 px

32x32 px

48x48 px

Tab

24x24 px

32x32 px

48x48 px

Dialog

24x24 px

32x32 px

48x48 px

List View

24x24 px

32x32 px

48x48 px

Table 2

5. How can I achieve adaptive screen size?

1) interface Layout

Five layout, similar to the title bar of the windos window), layout-small (layout with a screen size less than 3 inch), layout-normal (screen size less than 4.5 inch ), layout-large (between 4 inch and 7 inch), layout-xlarge (between 7 and 10 inch)

2) image resources

You need to prepare 5 sets of image resources, including drawable, drawalbe-ldpi, drawable-mdpi, drawable-hdpi, and drawable-xhdpi Based on the dpi value.

Android has an automatic matching mechanism to select the corresponding layout and image resources.

 

Http://blog.csdn.net/moruite/article/details/6028547

Length unit basics 1. Overview

In the past, programmers often designed computer user interfaces in pixels. For example, the image size is 80x32 pixels. The problem with this processing is that if you run the program on a new display with a dot (dpi) higher per inch, the user interface will look small. In some cases, the user interface may be small to difficult to see the content. Therefore, we can solve this problem by developing a program using a measurement unit unrelated to the resolution. Android Application Development supports different measurement units.

2. Meaning of measurement units

Dip: device independent pixels (device independent pixel ). different devices have different display effects, which are related to the hardware of the device. We recommend that you use this function to support WVGA, HVGA, and QVGA without pixels.

Dp: dip is the same

Px: pixels (pixels). Different devices have the same display effect. Generally, we use HVGA to represent 320x480 pixels, which is usually used.

Pt: point, a standard unit of length, 1pt = 1/72 inch, used in the printing industry, very easy to use;
Sp: scaled pixels (zoom in pixels). It is mainly used to display the best for textsize in fonts.

In (INCHES): the unit of length.
Mm (mm): the unit of length.

3. Conversion Formula of measurement units

In the android source code package TypedValue. java, we can look at the following functions:

Public static float applyDimension (int unit, float value,

DisplayMetrics metrics)

{

Switch (unit ){

Case COMPLEX_UNIT_PX:

Return value;

Case COMPLEX_UNIT_DIP:

Return value * metrics. density;

Case COMPLEX_UNIT_SP:

Return value * metrics. scaledDensity;

Case COMPLEX_UNIT_PT:

Return value * metrics. xdpi * (1.0f/72 );

Case COMPLEX_UNIT_IN:

Return value * metrics. xdpi;

Case COMPLEX_UNIT_MM:

Return value * metrics. xdpi * (1.0f/25.4f );

}

Return 0;

}

This function converts units to pixels.

Metrics. density: The default value is DENSITY_DEVICE/(float) DENSITY_DEFAULT;

Metrics. scaledDensity: The default value is DENSITY_DEVICE/(float) DENSITY_DEFAULT;

Metrics. xdpi: The default value is DENSITY_DEVICE;

DENSITY_DEVICE: screen Density

DENSITY_DEFAULT: The default value is 160.

 

4. Screen density: the number of display points per inch. The screen density is different from the resolution.

Android has the following screens:

Screen

Tyep

Width

Pixels

Height

Pixels

Dimensions

Range (inches)

Screen Density

QVGA

240

320

2.6-3.0

Low

WQVGA

240

400

3.2-3.5

Low

FWQVGA

240

432

3.5-3.8

Low

HVGA

320

480

3.0-3.5

Medium

WVGA

480

800

3.3-4.0

High

FWVGA

480

854

3.5-4.0

High

WVGA

480

800

4.8-5.5

Medium

FWVGA

480

854

5.0-5.8

Medium

Remarks

Currently, the default android low = 120; Medium = 160; High = 240

 

5. To sum up

Based on px = dip * density/160, when the screen density is 160, px = dip
According to google's suggestion, TextView'sIt is best to use sp as the unit for font size.And the source code of TextView shows that Android uses sp as the font size unit by default. Units that use dip as other elements.

 

 

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.