Android Adaptation _ Related concepts and applications

Source: Internet
Author: User

There are several concepts and related formulas to understand first:
1, dp:device independent pixels (device independent pixels), is the pixel and density ratio
DP = px/density

2, dpi (dot per inch) and PPI equal, is the screen diagonal pixel number and screen size ratio
DPI = PPI = (√ (screenheight^2 + screenwidth^2))/Screen size (inch)


3, the density is dpi and 160 ratio
Density = dpi/160

4, inch is the ratio of promises dpi or PPI
inch = PX/DPI = Px/ppi


Adaptation, according to their own understanding of the following two situations (with different views can be supplemented)

See first case (screen width same, resolution different)

1, a resolution is 480 * 800 of the mobile phone, width 480, high 800, the height of the general will be affected by virtual keys, etc., but the width is certain, to the width of the standard, so, generally by the width of the distinction

160dpi screen width of 3 inch,dp to 480DP

2, another resolution 720 * 1280 of the mobile phone width 720, high 1280

240dpi screen width is 3 INCH,DP same as 480DP

So, the two phone screens are the same size, but the resolution is different, so the same layout file with the same Dimens file is perfectly suited for these two phones
But the pictures, the same pictures, were placed in drawable-mdpi and drawable-hdpi,
On the first phone to show normal, on the second phone will appear small, so, high-density pictures should be bigger
(Note: If only a set of graphs, such as in the drawable-mdpi, the picture display size is the same)

Second case (same resolution, different screen width)

1, a resolution of 720 * 1280 mobile phone width 720, high 1280
160dpi screen width of 4.5 inch,dp to 720DP

2, a resolution of 720 * 1280 mobile phone width 720, high 1280
240dpi screen width of 3 inch,dp to 480DP

In the case of a situation, the picture will be in different sizes and the layout and size may be different now.
So, layouts and sizes need to be adapted if different sizes of screens require different layouts.
For example, the first phone, may be flat size, layout and mobile phone, layouts can not be applied to the tablet,
Therefore, you need to re-establish the folder re-layout such as LAYOUT-SW720DP
The second phone, layout is also different, need to establish LAYOUT-SW480DP

For different screen sizes, the view may also have different dimensions
There will be dimen.xml files in the values, so the dimensions also need to be adapted
The following directories may be created VALUES-SW720DP, VALUES-SW480DP

The format of SW720DP and SW480DP is as follows:
SW<N>DP (smallestwidth) screen toggle, the minimum screen width will not be changed
W<N>DP screen switch, screen width will vary according to the screen

The n refers to the screen width, the unit dp,720px different density, the width is different, so there will be different directories
This use is 3.2 before starting to use, before the use of small, normal, large, xlarge this
Examples of directory names:
LAYOUT-SW720DP, LAYOUT-SW480DP, LAYOUT-SW320DP, Layout-large, VALUES-SW480DP, etc.


To summarize, as far as the current self-understanding of the adaptation of the two cases
1, the screen width is the same, the resolution is different (suitable for different density pictures, different density of the style, theme, etc.)
2, the same resolution, different screen width (suitable for different layouts, suitable for different sizes)

In addition, from the directory structure generated by Android, there should be a third, suitable for different versions
such as values directory will have values-v11, VALUES-V14, inside only Style.xml,
are different themes that may be different versions of Android, themes are new, want to use the new UI interface in the new version, do the adaptation, unproven, just guessing.

The following documents are recommended for reading:

http://developer.android.com/guide/practices/screens_support.htmlhttp://developer.android.com/training/ Multiscreen/index.html

Android Adaptation _ Related concepts and applications

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.