Android screen adaptation

Source: Internet
Author: User

This post writes about Android screen adaptation

1, Picture text adaptation

When an Android project is built with the Eclipse development environment, the system generates DRAWABLE-LDPI, DRAWABLE-MDPI, drawable-hdpi, drawable-xhdpi, DRAWABLE-XXHDPI Five versions to accommodate different screens.

File directory Screen type Resolution Dpi DP|PX Correspondence Size Spec icon
drawable-ldpi QVGA 240*320 120 0.75x small 36*36
drawable-mdpi HVGA 320*480 160 1x 48*48
drawable-hdpi WVGA 480*800 240 1.5x large 72*72
drawable-xhdpi 720p 720*1280 Span style= "Font-family:microsoft Yahei; font-size:13px; " >320 2x SD 96*96
drawable-xxhdpi 1080P 1080*1920 480 3X Hd 144*144

Text conversion: 1SP = 2px; for example, 16sp = 32PX,14SP = 28px

2, some design principles:
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, the Wrap_content,match_parent or DP is better than PX, and 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) Use 9-patch PNG image
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.

3. Different layout
Android phone screen size is different, there are 480x320, 640x360, 800x480 ...
Let application automatically adapt to different screens, just need to create a different layout folder in the Res directory, such as: layout-640x360, layout-800x480 ... All layout files are written to R.java after compilation, and the system uses the appropriate layout according to the size of the screen.

Android phone model, screen resolution too much, it is difficult to take into account all, you can choose some representative model test: Xiaomi, Samsung, Huawei, ZTE ...

Android screen 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.