1, the use of wrap_content, match_parent, weight;
2, use the relative layout, try not to use absolute layout;
3, using qualifiers, such as: layout-large/xxx.xml, so large screen device will automatically use the layout;
4, use the minimum width qualifier, such as: Layout-sw700dp/xxx.xml, so that when the width of the screen more than 700DP will use the layout;
5, for different resolutions, to provide specific layout, such as: Res/layout-800x480/xxx.xml;
6. Using Layout aliases
For example, there is a layout mylayout.xml
Use Mainlayout as an alias in Layout-large/xxx.xml
<resources> <item name= "mainlayout" type= "layout" > @layout/mylayout</item> </ Resources>
7. Use. 9 picture, only need to have one in drawable below can;
8. Use DP,SP instead of PX as the unit of length;
9, provide different sizes of bitmaps, such as: MDPI,HDPI and other directories below to have a corresponding bitmap;
10, judge the layout of the load to decide to go the different processes, as follows:
Setcontentview (r.layout.main_layout);//This will load a different layout Button btn1 = (button) Findviewbyid (R.ID.BTN1) depending on the screen size;// One of the layouts does not have the button if (BTN1 = = null) { ...} else{... }
tips:
1, DP and PX conversion rules: 160dpi (Density) as the benchmark, 1dp=1px, if the density is 320dpi, then 1dp=2px, and so on.
2, mdpi,hdpi and other directories do not need to put all the tablets, this will make the APK occupies a larger storage space, it is recommended for those more important images to provide multiple resolutions, not very important only to provide a single.
Some suggestions on screen fitting for Android