How Android apps match different phone resolutions

Source: Internet
Author: User

From the help document provided by the Android SDK, we can see the resolution and corresponding screen size of various phones: QVGA (240x320), WQVGA400 (240x400), WQVGA432 (240x432), HVGA (320x480), WVGA800 (480x800), WVGA854 (480x854).
However, because of the different resolution, may cause the same layout corresponding to different resolutions of the phone display different effects, such as layout dislocation, image blur, then, how to solve this problem?
First, for the interface layout aspect
1, according to the size of the physical size to prepare 5 sets of layout layouts:
(1) Layout (put some common layout xml file) from the Help document provided by the Android SDK, we can see the resolution of various phones and the corresponding screen size: QVGA (240x320), WQVGA400 (240x400), WQVGA432 ( 240x432), HVGA (320x480), WVGA800 (480x800), WVGA854 (480x854).
However, because of the different resolution, may cause the same layout corresponding to different resolutions of the phone display different effects, such as layout dislocation, image blur, then, how to solve this problem?
First, for the interface layout aspect
1, according to the size of the physical size to prepare 5 sets of layout layouts:
(1) Layout (put some common layout xml file)
(2) Layout-small (screen size less than 3 inches or so of layout)
(3) Layout-normal (screen size less than 4.5 inches or so)
(4) Layout-large (between 4 "-7")
(5) Layout-xlarge (between 7-10 inches)
2. Configure different layout layouts according to the requirements.
such as: 240x320, the establishment of layout-320x240;400x800, the establishment of layout-800x400. It should be noted that the large write in front, for example 320, small write in the back, for example 240, and multiplication sign to be written in lowercase x, cannot be written as *.
In addition, if it is a generic layout file, it is placed under layout.

Finally note: For the interface layout of the resolution of the match need to add the following paragraph in the androidmanifest.xml, without this paragraph adaptive can not be achieved:
</application>
<supports-screens
Android:largescreens= "true"
Android:normalscreens= "true"
Android:smallscreens= "true"
Android:xlargescreens= "true"
Android:anydensity= "true"/>
</manifest>
Add the above code between the </application> tab and the </manifest> tag. Note: Due to the different Android version, some versions do not support Xlargescreens, you can directly remove the android:xlargescreens= "true".
Note: android:anydensity=["true" | "False"]
If android:anydensity= "true" means that the application supports different densities, it will automatically match according to the resolution of the screen.
If android:anydensity= "false", the application supports different densities, the system automatically scales the image size and coordinates of this image. Explain how the system automatically scales resources. For example, we have the same resource under the Hdpi,mdpi,ldpi folder, then the application will not automatically go to the appropriate folder to find resources, this situation is in high-density, and low-density mobile phones, such as a 240x320 pixel phone, if set up Android: Anydensity= "false", the Android system will convert the x 320 (low density) to 320x480 (medium density) so that the application will load the resources in the mdpi file on the small-density phone.

Second, the picture resources aspect
1, need to prepare 5 sets of picture resources according to the DPI value:
(1) Drawable: Primary placement of XML configuration files or images with lower resolution requirements
(2) drawalbe-ldpi: Low-resolution images, such as QVGA (240x320)
(3) DRAWABLE-MDPI: Medium resolution picture, such as HVGA (320x480)
(4) DRAWABLE-HDPI: High resolution pictures, such as WVGA (480x800), FWVGA (480x854)
(5) drawable-xhdpi: At least 960DP x 720DP (less commonly used)
Android will have automatic matching mechanism to select the corresponding layout and image resources, the system will be based on the resolution of the machine to find the corresponding image of each folder.
Three, dynamic implementation of the interface, style settings (values)
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: Creating a values-480x320 values-800x400 in res
and create String.xml in the folder you created.
<dimen name= "Text_size" >30px</dimen>
Calling R.dimen.text_size directly in the program

Finally, make a summary:
(1) Do not use absolutelayout layout, try to use relativelayout and linearlayout;
(2) When using the layout as far as possible to use the weight, can effectively reduce the usage of dead data, reduce the workload of adaptation.
(2) Layout-small (screen size less than 3 inches or so of layout)
(3) Layout-normal (screen size less than 4.5 inches or so)
(4) Layout-large (between 4 "-7")
(5) Layout-xlarge (between 7-10 inches)
2. Configure different layout layouts according to the requirements.
such as: 240x320, the establishment of layout-320x240;400x800, the establishment of layout-800x400. It should be noted that the large write in front, for example 320, small write in the back, for example 240, and multiplication sign to be written in lowercase x, cannot be written as *.
In addition, if it is a generic layout file, it is placed under layout.

Finally note: For the interface layout of the resolution of the match need to add the following paragraph in the androidmanifest.xml, without this paragraph adaptive can not be achieved:
</application>
<supports-screens
Android:largescreens= "true"
Android:normalscreens= "true"
Android:smallscreens= "true"
Android:xlargescreens= "true"
Android:anydensity= "true"/>
</manifest>
Add the above code between the </application> tab and the </manifest> tag. Note: Due to the different Android version, some versions do not support Xlargescreens, you can directly remove the android:xlargescreens= "true".
Note: android:anydensity=["true" | "False"]
If android:anydensity= "true" means that the application supports different densities, it will automatically match according to the resolution of the screen.
If android:anydensity= "false", the application supports different densities, the system automatically scales the image size and coordinates of this image. Explain how the system automatically scales resources. For example, we have the same resource under the Hdpi,mdpi,ldpi folder, then the application will not automatically go to the appropriate folder to find resources, this situation is in high-density, and low-density mobile phones, such as a 240x320 pixel phone, if set up Android: Anydensity= "false", the Android system will convert the x 320 (low density) to 320x480 (medium density) so that the application will load the resources in the mdpi file on the small-density phone.

Second, the picture resources aspect
1, need to prepare 5 sets of picture resources according to the DPI value:
(1) Drawable: Primary placement of XML configuration files or images with lower resolution requirements
(2) drawalbe-ldpi: Low-resolution images, such as QVGA (240x320)
(3) DRAWABLE-MDPI: Medium resolution picture, such as HVGA (320x480)
(4) DRAWABLE-HDPI: High resolution pictures, such as WVGA (480x800), FWVGA (480x854)
(5) drawable-xhdpi: At least 960DP x 720DP (less commonly used)
Android will have automatic matching mechanism to select the corresponding layout and image resources, the system will be based on the resolution of the machine to find the corresponding image of each folder.
Three, dynamic implementation of the interface, style settings (values)
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: Creating a values-480x320 values-800x400 in res
and create String.xml in the folder you created.
<dimen name= "Text_size" >30px</dimen>
Calling R.dimen.text_size directly in the program

Finally, make a summary:
(1) Do not use absolutelayout layout, try to use relativelayout and linearlayout;
(2) When using the layout as far as possible to use the weight, can effectively reduce the usage of dead data, reduce the workload of adaptation.

Original from http://blog.sina.com.cn/s/blog_8a30865f0101j2wd.html


How Android apps match different phone resolutions

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.