androiddimensionslayer-listandroid-splashscreen

Dimensions of a PNG file to match exactly with Android drawable dp


I want to use the PNG format of my Android studio drawable logo in splash-screen for APIs 21 and 22. As it has been noted in this post, these APIs have problems with drawables in layer-list. So I want to convert my drawable file into a PNG format file (using Adobe AI or CorelDraw, etc), but I don't know exactly what dimensions I should save my file to match exactly with Android drawable dp.

My drawable logo size is 100dp x 100dp. What dimensions should I export my file to? Is that just one file, or should I export 5 different sizes for idp, mdp, xdp, xxdp and xxxdp? I am aware that layer-list doesn't support @mipmap resource.

Here is a programmatic way that provides the following unit-conversion formula

pixels = dps * (density / 160)

But do I have to have a PNG file for each density?

Update: I tried to use the above formula or online unit-convertors but the result was so bigger that what I expedted. for my logo that is 100*100 dp*pd I created a PNG format logo with dimensions 187.5*187.5 px*px and with dpi 300, that was bigger that 100*100 dp*pd!


Solution

  • As you can see from the formula you quoted, the number of pixels is dependent on the density of the display.

    So, if you want to match your image size in pixels exactly to the dps, then you would need a separate image for each density.

    I'm not saying that doing this is necessarily a good or bad idea, just answering exactly what you asked.