Analysis of the relationship between screen density and image size in Android

Source: Internet
Author: User



Many resources are supported in Android, including images (Bitmap), and folders corresponding to Bitmap are drawable, in addition to Drawable, drawable-ldpi, drawable-mdpi, drawable-hdpi, DRAWABLE-XHDPI, drawable-xxhdpi, and so on, the same picture in the above different folders there is a difference, such as a 100 * 100 pixel size of the picture, respectively, placed in each of the above folders, Then set it to ImageView (assuming the width is wrap_content) of the picture, then the size of the ImageView, or the size of the picture? This article mainly and everybody elaborated this question. Of course, there is another problem, if you put a picture in each of the above folders (the same content, different sizes), then the system will choose which image to load? This problem, the system has an internal selection mechanism, simple: The system will choose the closest to the screen density of mobile images, because this issue and the topic of this article is not very large, so for the time being do not discuss such issues.


First introduce some concepts:

Screen density: pixel points per inch area

LDPI: Mobile device with a screen density of 120

MDPI: Mobile device with a screen density of 160 (this is baseline, others are based on this, 1DP = 1px on this device)

HDPI: Mobile device with a screen density of 240

XHDPI: Mobile device with a screen density of 320

XXHDPI: Mobile device with a screen density of 480

Picture size and a list of DP and PX relationships

Note: According to the table above, we should easily figure out how wide and high a picture is on different phones.


We can draw conclusions from the above table.

1. The picture is placed in the drawable, equivalent to placed in the drawable-mdpi, because: drawable directory does not have screen density characteristics, so the reference value, that is MDPI

2. Picture is placed in a specific drawable, such as drawable-hdpi, if the device's screen density is higher than the current drawable directory represents the density, the picture will be magnified, otherwise it will be reduced

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

3. For a more comprehensive adaptation of all equipment, we should provide a picture of the mainstream screen density (currently hdpi or xhdpi), and other densities are automatically scaled to get pictures

Analysis of the relationship between screen density and image size in Android

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: 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.