Android-multi-screen adaptation related

Source: Internet
Author: User

1. Basic Concepts

Screen Size – The actual size of the screen, measured by the diagonal length of the screen (e.g. 3.4-inch, 3.8-inch). Android divides the screen into the following 4 types: Small,normal,large,extra large.
How to judge?

Screen Density -How many pixels are in a real screen area, usually measured in dpi (how many dots per inch). Compared to the medium, high screen density of the device, in a certain size of the screen area L density low of the screen has fewer pixels. Android divides the screen density into 4 types: Low,medium,high,extra high.

How to judge is ldpi,mdpi,hdpi?

Direction (orientation) -the screen orientation is divided into landscape (horizontal screen) and portrait (vertical screen).

Resolution (Resolution) -The total number of actual pixels on the screen. When a screen is adapted, it is generally not concerned with its resolution, only its screen size and density.

Density-independent pixels (density-independent PIXEL,DP or dip) -to ensure that your UI is suitable for different screen densities, it is recommended that you use DP to define the program UI.
It is calculated by: px = DP * (dpi/160)

SP (scale-independent pixel)

How to distinguish a screen is ldpi, MDPI, hdpi method, see

2, how to adapt to a variety of screens

A. Define the screen types supported by your program in manifest and the corresponding code is as follows:

<Supports-screensandroid:resizeable=["true" |"false"]android:smallscreens=["true"| "false"]//Support small screen android:normalscreens=["true"| "false"]//whether to support the screen Android:largescreens=["true"| "false"]//whether to support large screen Android:xlargescreens=["true"| "false"]//whether to support large screen android:anydensity=["true"| "false"]//whether to support a variety of different densities of screen ANDROID:REQUIRESSMALLESTWIDTHDP= "integer"ANDROID:COMPATIBLEWIDTHLIMITDP= "integer"ANDROID:LARGESTWIDTHLIMITDP= "integer"/>

B. Provide different layout for different sizes of screens.

For example, if you need support for a screen of size large, you need to create a new folder in the Res directory layout-large/and provide layout. Of course, you can also set up in the Res directory Layout-port and layout-land two directories, respectively, a vertical screen and two horizontal screen layout files to adapt to the vertical screen screen automatically switch.

C. provide different images for different densities of screens.
  Should try to use a point 9 format of the picture, if you want to the low density of the screen to provide the appropriate picture, you need to create a new folder drawable-ldpi/, and put in the appropriate size of the picture. Accordingly, the medium corresponds to drawable-mdpi/,high corresponding to Drawable-hdpi/,extra high corresponding to drawable-xhdpi/.
The size of the picture is determined: the Low:medium:high:extra high ratio is 3:4:6:8. For example, for medium density (medium) screens where your picture pixel size is 48x48, the low-density screen should have a picture size of 36x36, and a high of 72x72,extra for 96x96.

3, 4 Gold Principles for multi-screen adaptation
a. Wrap_content,fill_parent and DP should be used when setting control dimensions in the layout file.

specifically, the Wrap_content,fill_parent or DP is better than the PIX when setting the values of the view's properties Android:layout_width and Android:layout_height. Correspondingly, the screen should use the SP to define the size of the text in order for the text to fit better .

B. Do not show specific pixel values in the code of the program.

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.

C. Do not use Absolutelayout (android1.5 is obsolete). Accordingly, the relativelayout should be used.

D. Provide a picture of the right size for different screens. See part 2nd above.

4, the need to pay attention to the place
The above settings apply to versions below android3.2.

5. How to test whether your program supports multi-screen adaptation
It is common to use AVD Manager to create multiple emulators of different sizes, such as

More reference:http://www.cnblogs.com/laxlerbo/p/3868003.html

 

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.