0
votes

I have always noticed that i have many drawable directories - drawable hdpi, ldpi, mdpi, xhdpi. I know that these directories are for different screen densities(scaling up purposes, like android will use an image from hdpi if your screen has that screen density. But isnt that the whole point of the unit dp? Why invent the wheel again?

1
How do you figure you are re-inventing the wheel with the different folders?tyczj
because its the same concept as dp? Why not just the dp unit and not worry about the different folders?committedandroider

1 Answers

3
votes

When you describe a view size with dp units, you're only saying how much space it should take up on the screen. In the case of of a drawable, the renderer will scale the raw image up or down to fit your dimensions. The reason for the different drawable folders is to optimize for different resolutions.

On a screen device with higher pixel density, the interpolation performed by the renderer will make a low resolution raw image look blurry, which is why we need high resolution assets.

On a screen with low pixel density, the renderer can and will scale down high resolution images when low resolution ones aren't present, but this is wasteful. First of all, the interpolation performed by the renderer might give you an ugly result. Secondly, the raw image is decoded at full resolution only to be displayed in a view of a much smaller size. Thats wasting CPU cycles and memory, both of which tend to be less plentiful on devices with low pixel densities.