Considerations for screen adaptation 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. 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.
3.4 Gold Principles for multi-screen adaptation
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.
4. 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.
It is important to note that when doing 9patch, try to leave 2 pixels of space around.
Some common sense with Android screen adaptation