Some summary of Android multiple Screens Android screen adaptation

Source: Internet
Author: User

As an Android application development program Ape, the most painful thing is to adapt to the screen, which is related to historical reasons, specifically do not delve into.

Until recently to understand how the DPI conversion, in the development process, an application to run the screen should be a resolution of 320x480 density of 160dpi screen, so all placed in drawable, drawable-mdpi, values, layout, The Layout-normal resource file size unit is PX,1DP = 1px. For example, there is a wide 30px high 45px picture placed in the drawable-mdpi directory, the corresponding DP unit is 30DP x 45DP. Then the width of this picture placed in the drawable-hdpi directory should be 30*1.5px, high 45*1.5px,240/160=1.5. The natural place in drawable-xhdpi is 30*20px and 45*2px,320/160=2.

However, many companies develop apps that don't just develop Android versions, usually developed with iOS, and the artwork does a lot of work for Android to do four sets of diagrams (ldpi, MDPI, hdpi, xhdpi). The practice is to use the image in iOS 640x960 resolution, so as long as a set of pictures can be adapted to the standard Android phone screen, the so-called standard is the density of 160dpi, resolution of 320x480, density of 240dpi, The screen resolution is 480x800, of course, not including the tablet, this kind of tablet usually refers to the domestic tablet, the screen is large, but the resolution is small, this category is not included.

So how to use the iOS 640x960 picture to fit, 640x960 resolution in the Android system should be 320dpi density, so put this kind of picture in the drawable-xhdpi directory, and then in use, Usually layout files are placed in the layouts directory, which is used by 160dpi, so we need to xhdpi the picture in a processing, that is, the width of the height divided by 2,320/160=2.

For example, a login button picture, ios corresponding to the 640x960 resolution, the size of 72x64, when used in Android to put the picture in the xhdpi directory, when used to define the width of the high

<imageview    android:layout_width="36DP"android:layout_height="32DP"  ANDROID:SRC="@drawable/image"/>         

The goal is to make the image in the Android Auto-conversion without distortion problem, the picture from the big to small turn is not distorted, the effect is maintained. 36DP is obtained by 72/2, why divided by 2, is to the picture is for the 320dpi screen design, but the layout file is in the layout directory, that is, the layout is designed for the 160dpi screen, so need to convert to 160dpi standard density.

When the app is running on a 240dpi-density screen, the image is automatically converted from 160dpi to 240dpi, which is 36*1.5DP, 32*1.5DP. The actual is 72*0.75DP, 64*0.75, the picture is just for zooming, because there is no problem of distortion.

This approach allows the image to be adaptive to the four standard densities of 120, 160, 240, 320, which is a proportional autoscale process. At the same time the picture does not have the problem of distortion. Just if the content is too much in the 120-density screen look very ugly, the reason is to reduce a picture from the 72x64 to the 27x24.

Reprint: http://blog.linguofeng.com/archive/2013/05/02/Android-Multiple-Screens.html

Related Article

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.