Some suggestions on screen fitting for Android

Source: Internet
Author: User

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

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.