Android calculates the minimum width when the minimum width Delimiter is used.

Source: Internet
Author: User

Android calculates the minimum width when the minimum width Delimiter is used.

One of the biggest headaches in Android development is compatibility with devices of different sizes and resolutions. Here we recommend a complete summary of Android development: the most comprehensive and easy-to-understand Android screen adaptation solution. This article details many issues related to screen compatibility. Here we only add one point about how to calculate the minimum width when using the minimum width qualifier.

You can use a value that is independent of the pixel density of the screen (dp) to apply different resources. For example, the sw in the values-sw600dp represents the minimum width, then how is 600dp determined?

For example, we can easily know the resolution and size parameters of the device. For example, there are currently flat A (resolution: 1280*8 inch PX, size: 1920), mobile phone B (resolution: 5.7*1280 PX, size: inch), mobile phone C (resolution: * PX, the size is 5 inch ). Using the following formula for calculating the pixel density on the screen, we can calculate their pixel density respectively:

Tablet A is about 184 dpi, cell phone B is about 386 dpi, and cell phone C is about 293 dpi.

Next, you should note that the minimum width does not consider the horizontal or vertical screen. That is to say, the minimum width is the two shortest edges in the four screens of the device. You can add screen direction delimiters if you need to consider the horizontal and vertical screens, which is not discussed here. Then, we take the number of edges of the shortest side and calculate the minimum width (dp) using the formula below ):

Tablet A is about 626dp, cell phone B is about 448dp, and cell phone C is about 393dp.

 

As shown above, 600dp can be used to distinguish between tablets and mobile phones. If you need to distinguish between mobile phone B and C in detail, you can set sw400dp as the difference.

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.