Android adaptable to different dpi and screen sizes

Source: Internet
Author: User

First, Introduction

Android's Open source so that manufacturers do not have to develop their own OS, greatly reducing the cost of research and development, production, so that the Android tablet brand has sprung up, cottage manufacturers seem to find a glimmer of hope. At the same time brings the vast number of developers miserable, all kinds of magical small board test the compatibility of the app, a variety of custom ROM inadvertently let the app crash, just the adjustment on the interface is enough for you to drink a pot, is not?

second, the suitability of the feasibility

this has been taken into account in the early days of Android design, and Google has a proven solution in order to adapt the app to the standard or cottage screen. Among them, there are several indicators to note:

(1) Screen size: unit inch, refers to the screen diagonal length.

(2) screen density: unit dpi, refers to the number of pixels per inch can be displayed as PX.

(3) Screen resolution: the Unit PX * px, refers to a screen display how many pixels.

(4) screen-independent pixels: unit Dp/dip, which refers to pixels that are adaptive to the screen density, to specify the control's height.

(5) scale-independent pixels: unit SP, which is the pixel of the adaptive font that specifies the size of the text.

take my own Haier W910 super battleship (aspect ratio 16:9) For example, the conversion of the above units is as follows:

Known data: Screen size 4.5, resolution 1280 * 720, screen density

(1) 16:9 of the 4.5-inch screen by the Pythagorean theorem to calculate its height of about 3.9 inches, about 2.2 inches wide

(2) The vertical dpi is 1280/3.9≈328 and the horizontal dpi is 720/2.2≈327

(3) Industrial cutting LCD board when rounding is

so since the DPI is adaptive screen density, and the PX is how to convert it:

120dpi (ldpi low-density screen) 1DP = 0.75px (because the pixel is a physical point, so the content of 3 DP is displayed with a 2-pixel point)

160dpi (mdpi medium density screen) 1DP = 1px

213dpi (tvdpi TV density screen) 1DP = 1.33px

240dpi (hdpi high-density screen) 1DP = 1.5px

320dpi (xhdpi Ultra high-density screen) 1DP = 2px

from the above analysis results, the control using DP, the text using SP can meet the adaptive requirements.

third, the adaptation scheme

According to the current survey, the market in the flat, basically belong to MDPI and hdpi, a few belong to tvdpi (such as Google out of the NEXUS7), so we choose these three density to consider adaptation; In addition, most of the mobile applications are vertical screen, but the tablet as an entertaining product, When the screen is used, we also need to consider the screen state to adapt, and finally consider that some ROM will calculate the virtual key to the screen size, but also take into account the virtual key occupied by the length of the width.

So how do you adapt to these three attributes? Android in the resource file in the form of a filename to provide qualifiers can help us to judge the above situation, the qualifier (MDPI,TVDPI,HDPI) can help us determine the screen density, qualifier (land,port) can help us to distinguish screen status, and qualifiers (1024x600 ...) For a screen that calculates virtual keys or does not compute virtual keys, refer to the supporting multiple screens topic in the Developer's Guide in the Android SDK documentation for a detailed description of the qualifier.

The final adapter folder looks like this:

  

Note 1: The resolution qualifier match is down, if there is no values-land-mdpi-1024x552, for example, the resolution values-land-mdpi-1024x600 screen, when the ROM does not calculate the virtual key to the screen size, The actual screen should be values-land-mdpi-1024x552 and not fit into the values-land-mdpi-1024x600, which may be appropriate to the next level, such as values-land-mdpi-800x480, But now the tablet is not so low resolution, so it is equipped with infinite fixed values-mdpi, resulting in the interface display flaws.

NOTE 2: Because the match of the resolution qualifier is down, the values-mdpi can at least guarantee that the app will not crash if there are non-mainstream MDPI screens that cannot be accurately adapted to the above specified values. The same values guarantee that the LDPI screen's tablet will not crash because the view is generated and the corresponding value is not taken.

Android is adaptable to different dpi and screen sizes

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.