Android about resource adaptation

Source: Internet
Author: User


I. About picture Resources


Picture width high do not fixed size, in small screen and large screen, different frequency, using different pictures, this to art transduction.


Different resolution, the interface aspect ratio is inconsistent, need different specifications of the picture in the drawable-hdpi,drawable-ldpi,drawable-mdpi to put different resolution picture note: In order to reduce the overall application package size, choose the highest resolution adaptation, Special Interface Picture Special processing


Two. About layout adaptation.


Android phone screen size is different, there are 480x320,640x360,800x480. How can I get the app to adapt to various screens automatically? In fact, it is very simple to create a different layout folder in the Res directory, such as: layout-640x360,layout-800x480, all layout files will be written to R.java after compilation, and the system Depending on the size of the screen, you can choose the appropriate layout to use.




1. try not to use absolute layout


2. Use match_parent as much as possible, do not use fill_parent, when setting the length in the layout, it is best to use wrap-content,match-parent, the text to use the SP, pixels to use DIP/DP.


3.be able to use heavy places as far as possible to use the weight (android:layout_weight).

4.if it's a solid color background, try using the Android shape customization

5. If you need to fit at a specific resolution, you can create a new Layout-hxw.xml folder on the Res directory.

For example, to fit the 1080*1800 screen (Meizu MX3 with this resolution), create anew layout-1800x1080.xml folder and define the layout below. The Android system will first look for layouts with the same resolution and, if they don't exist, use the default layout under layouts.




Different resolutions, the font size of the interface, fonts, etc. need different styles, and need to be dynamically generated in the case, you need to save the configuration information of different resolutions to the application. Example: Create values-480x320 values-800x400 value-1280x720 in res  and create Dimens.xml<dimen name= "Text_size" in the Created folder > 30px</dimen> calls R.dimen.text_sizeint Sizeoftext = (int) this.getresources () directly in the program. Getdimension (R.dimen.Text_ size); Note: The actual application found that the font size adaptation, such as only the following screen font values-480x320 values-800x480  value-1280x720 When a phone screen resolution of 854x480 will automatically find the maximum font adaptation ( value-1280x720) Summary: If the font 800x480 above does not fit, the phone automatically according to the maximum resolution adaptation.





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.