Android: Common Resolutions (MDPI, HDPI, xhdpi, xxhdpi) and screen adaptation considerations

Source: Internet
Author: User

1 common resolutions for Android phones today

1.1 Common resolutions for mobile phones:

4:3
VGA 640*480 (Video Graphics Array)
QVGA 320*240 (Quarter VGA)
HVGA 480*320 (half-size VGA)
SVGA 800*600 (Super VGA)

5:3
WVGA 800*480 (Wide VGA)

16:9
FWVGA 854*480 (full Wide VGA)
HD 1920*1080 HD
QHD 960*540
720p 1280*720 SD
1080p 1920*1080 HD

1.2 Resolution corresponds to DPI
"HVGA-------->mdpi"

"WVGA-------->hdpi"
"FWVGA-------->hdpi"
"QHD-------->hdpi"
"720P-------->xhdpi"
"1080P-------->xxhdpi"

2 Considerations for Screen adaptation 2.1 basic settings

2.1.1 Androidmanifest.xml settings

Adding child elements in Menifest

Android:anydensity= "true" when the application is installed on a different density terminal, the program loads the resources in the xxhdpi, xhdpi, hdpi, MDPI, ldpi folders, respectively.

Conversely, if set to False, the app does not automatically look for resources under the folder, even if it has the same resources under the folder:

1) If the drawable-hdpi, drawable-mdpi, drawable-ldpi three folders have a different density of the same picture resource, then the system will load the resources in the DRAWABLE_MDPI folder;

2) If there are high-density images in the drawable-hpdi, the other two folders do not have the corresponding picture resources, then the system will load the resources in the drawable-hdpi, other similar;

3) If there is a picture resource in the drawable-hdpi,drawable-mdpi, drawable-ldpi does not, the system will load the resources in drawable-mdpi, other similar, use the closest density level.

2.1.2 Horizontal Screen Vertical screen catalog distinguish

1) drawable

A) drawable-hdpi the picture is applicable to the horizontal screen, but also for the vertical screen;

b) drawable-land-hdpi, when the screen is horizontal screen, and is high density, load the resources of this folder;

c) drawable-port-hdpi, load the resources in this folder when the screen is vertical and high density. The other same.

2) Layout

In the Res directory, the establishment of the Layout-port and Layout-land two directories, respectively, a vertical screen and two horizontal screen layout files, to adapt to the horizontal screen vertical screen automatically switch.

2.2 Multi-screen fit 4 gold principles

1) fill_parent, Wrap_content, Match_parent, and DP should be used to set the control dimensions in the layout file;

Specifically, when setting the values of the view's properties Android:layout_width and Android:layout_height, thewrap_content,match_parent or DP is better than PX, The text size should be defined using the SP .

2) do not appear in the code of the program specific pixel values, defined in the Dimens.xml;

To make the code simple, Android internally uses the PIX to represent the size of the control, but this is based on the current screen. To accommodate multiple screens, Android recommends that developers not use specific pixels to represent the size of the control.

3) do not use Absolutelayout (android1.5 is obsolete), you can use relativelayout substitution;

4) provide a suitable size picture for different screens.

Different size of the screen with different size of the picture, Low:medium:high:extra-high picture size ratio of 3:4:6:8; For example, for medium density (medium) screen your picture pixel size is 48x48, then low density The picture size of the screen should be 36x36, and the height (high) is 72x72,extra-high for 96x96.

2.3 Using 9-patch PNG images

When using the picture resource, if there is a stretch, because the picture processing reason, will deform, cause the interface shape. The 9-patch PNG image is also a standard PGN image, vacated by a pixel interval around the native PNG image, to identify which parts of the PNG picture can be stretched, which cannot be stretched, the border position on the background, and so on.

"Top, left" defines an extruded area

"Right, bottom" defines the display area, and if you use a full-filled background map, it is recommended that you do not set the margin by android:padding, but by 9-patch way.

The Android SDK provides tools to edit 9-patch images, Draw9patch.bat in the tools directory to instantly see the edited stretch, or edit directly with other image editing tools, but no effect is visible.

2.4 Different layout

Android phone screen size is different, there are 480x320, 640x360, 800x480 ...

How can application automatically adapt to different screens?

In fact, it is very simple, just need to create a different layout folder in the Res directory, such as: layout-640x360, layout-800x480 ... All layout files are written to R.java after compilation, and the system uses the appropriate layout according to the size of the screen.

2.5 Test Verification

In general, using AVD Manager to create a number of different sizes of the simulator, if the conditions are available, you can also directly use the real machine test, this is more reliable.

Android: Common Resolutions (MDPI, HDPI, xhdpi, xxhdpi) and screen adaptation considerations

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.