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.