简体   繁体   中英

What is the optimal bitmap size for drawable ldpi / mdpi / hdpi / xhdpi folders?

I want to scale images such that they fit optimally the screen size and don't consume more memory than required.

Currently I put images made for a 640 x 960 screen in hdpi folder, it looks good, but it consumes a lot more memory than necessary. A 480 x 800 device, for example, is hdpi and will load these bitmaps.

Since most hdpi devices I know are 480 x 800, my first thought would be to scale down all the images in hdpi to fit a 480 x 800 screen. But I'm not sure, since hdpi doesn't refer to only to resolution, but density.

It's confusing since the folders refer to density, but the bitmaps are just pixels, and I don't know how to assign them there...

Any help is greatly appreciated.

To give more context: The thing is that I have a bitmap animation with more than 20 bitmaps each 640 x 588 px. So, on some devices this alone will run in out of memory. The memory occupied with 640 x 588 is 1.43 mb each bitmap !. If I scale down to 480 x 441 I get 0.80 mb and that's a huge improvement. And since in a 480 x 800 device I'll not lose detail, I would scale all the tiles down.

In my opinion, images sized to fit the full screen are just not a good idea for Android in general . That said, if it's what you need to do, I would worry less about the memory usage and opt for the largest size you think you will need for a particular density, and just let the OS scale down from there for small variances in screen size. Don't forget you can also specify drawables by screen size as well (eg drawable-large-hdpi ) if you need to get more specific.

Depending on the image, if it's possible to make any part of the background stretchable, I would recommend making it a 9-patch, and sizing it to fit the smallest screen in that density bucket and let it fit to the screen that way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM