Detailed explanation of the relationship between screen density and picture size in Android

Detailed explanation of the relationship between screen density and picture size in Android

preface

Android supports many resources, including bitmap. The folder corresponding to bitmap is drawable. In addition to drawable, there are drawable LDPI, drawable MDPI, drawable hdpi, drawable xhdpi, drawable xxhdpi, etc. it is different to put the same picture in different folders above, such as a picture with the size of 100 * 100 pixels, Put them in the above folders respectively, and then set them as images of ImageView (assuming that the width and height are wrap_content). What is the size of this ImageView, or the size of the image? This paper mainly expounds this problem with you. Of course, there is another problem. If the same picture (the same content and different sizes) is placed in each of the above folders, which picture will the system choose to load? For this problem, the system has an internal selection mechanism. To put it simply, the system will select the picture closest to the screen density of the mobile phone. Since this problem is not closely related to the theme of this article, such problems will not be discussed for the time being.

concept

First introduce some concepts:

Screen density: number of pixels per inch area LDPI: mobile phone device with screen density of 120 MDPI: mobile phone device with screen density of 160 (this is baseline, others are based on this, 1DP = 1px) hdpi: mobile phone device with screen density of 240 xhdpi: mobile phone device with screen density of 320 xxhdpi: mobile phone device with screen density of 480

List of picture size and DP and PX relationship

Note: according to the above table, it should be easy to calculate the width and height of a picture on different mobile phones.

conclusion

The following conclusions can be drawn from the above table

1. Putting pictures in drawable is equivalent to putting them in drawable MDPI. The reason is that drawable directory does not have screen density characteristics, so the reference value, MDPI, is adopted

2. The picture is placed in a specific drawable, such as drawable hdpi. If the screen density of the device is higher than that represented by the current drawable directory, the picture will be enlarged, otherwise it will be reduced

Zoom in or out = device screen density / screen density represented by drawable directory

3. In order to more fully adapt to all devices, we should provide a set of pictures for mainstream screen density (currently hdpi or xhdpi), and other densities can be automatically scaled by the system

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>