Android multi-resolution adaptive summary, android adaptive

Source: Internet
Author: User

Android multi-resolution adaptive summary, android adaptive
This week's work adjusted the multi-resolution adaptation of the Android project. Therefore, we are constantly trying to learn this knowledge. At the beginning of the Android project, you must develop programming habits. All resource calls are placed in value. Uniform Naming and management. Summarized the following content.

I. general basic principles and summary
1. Do not die in xml layout. Do not use px, dp, or match or warp as much as possible.
2. design resource images as tensile images as much as possible. 9. If there is a gradient, try to horizontal or vertical single-direction gradient. This can greatly reduce the installation package size and increase the processing speed.
3. If you do not want to design multiple sets of images, design the largest set. Compression is better than stretching. Put it in the drawable-xhdpi folder.
4. Write several sets of value values, corresponding to different resolutions. A set of layout. As shown in.



5. Create multiple layout folders, the folder name is layout-800x480, etc. To adapt to that resolution, write it as anything. (This method is too tired and will lead to large applications, which is not recommended)

6. You have to rewrite some layout xml files.
Layout-1024x768
Layout-1024x600
Layout-1280x768
Layout-land-1024x720 // 1024x768 landscape Screen
Layout-port-976x768 // 1024x768 portrait Screen
Note the format. [layout]-[port/land]-[length x Width]
Note:
To adapt to the above resolution after android, the height must be reduced by 48 pixels, that is, the height of the status bar at the bottom, which can be recognized by android.
A large number in the resolution must be written to the front; otherwise, a syntax error occurs.

7,

<supports-screensandroid:largeScreens="true"android:normalScreens="true"android:anyDensity = "true"/>
Android: anyDensity = "true", which plays a very important role in the entire screen. The value is true. When our applications are installed on mobile phones of different density, the program loads Resources in the hdpi, mdpi, and ldpi file folders respectively.

Add the above Code between the </application> label and the </manifest> label. You can.

2. Attach the Android screen resolution and pixel knowledge.
Low Density (120), ldpi
Medium Density (160), mdpi
High density (240), hdpi
Small Screen
1. QVGA (240x320), 2.6 ~ 3.0 inch
Normal Screen
1. WQVGA (240x400), 3.2 ~ 3.5 inch
2. FWQVGA (240x432), 3.5 ~ 3.8 inch
3. HVGA (320x480), 3.0 ~ 3.5 inch
4. WVGA (480x800), 3.3 ~ 4.0 inch
5. FWVGA (480X854), 3.5 ~ 4.0 inch
Large Screen
1. WVGA (480x800), 4.8 ~ 5.5 inch
2. FWVGA (480X854), 5.0 ~ 5.8 inch

The screen sizes include small, normal, large, and xlarge, which respectively indicate small, medium, large, and ultra-large screens.
The screen density is divided into ldpi, mdpi, hdpi, and xhdpi. Their standard values are 120 dpi, 160 dpi, 240 dpi, and 320 dpi.

Px (pixel): the point on the screen.
In (INCHES): the unit of length.
Mm (mm): the unit of length.
Pt (lbs): 1/72 inch.
Dp (density-independent pixels): An abstract unit based on screen density. 1dp = 1px on a display at 160 o'clock per inch.
Dip: it is the same as dp and is mostly used in android/ophone examples.
Sp (pixels irrelevant to the scale): similar to dp, but can be scaled based on the user's font size preferences.

Therefore, according to google's suggestion, it is best to use sp as the unit of TextView font size, and to view the TextView source code, Android uses sp as the font size unit by default.

Suggestions for choosing sp and dp are as follows:
1. If the display area of textview can be elastically changed (wrap_content, of course, all its parent views must be elastically changed), sp can be used as a priority, changing the font size will not compromise the availability of the interface.

2. In contrast to 1, the display area of textview is limited to a fixed value (or its parent view is limited). In this case, dp is preferred, otherwise, the user who has been using a large font may be intercepted horizontally, but the user does not know it, it may be a program problem.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.