Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we need to add all images with different dpi to Android Apps

As you know Android applications have different DPIs and also in the Android applications we can add drawables with diffrent DPIs in diffrent ldpi, mdpi, hdpi and xhdpi folders.

The question is that when we want to support all DPIs we should add the icons with all different sizes or just with the biggest one?

I mean for example suppose that I have one action bar item with icon. Whether I should add the icon of this action bar item with 24x24(in drawable-mdpi folder),36x36 (in drawble-hdpi folder),48x48 (in drawable-xhdpi folder),.....

Or I just need to add one icon with size 96x96 in xxxhdpi folder and android will set the icon for other DPIs with good quality?

like image 283
Husein Behboudi Rad Avatar asked Sep 30 '22 12:09

Husein Behboudi Rad


1 Answers

TLDR see the bold below

Different density folders were added later on for Android which means that...

If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.

If you want to have complete control over how the assets are scaled then you can by all means provide your own for all / some of the densitys. In practise I generally provide HDPI / XHDPI as above and give all the resource buckets for things like logos / AB icons / App icons etc. I generally find the auto scaling to be pretty good and work for most situations, but will occasionally have to supply and extra LD/MD asset if its a small asset / contains small text etc. Plus if i duplicated all assets for things like XXXHDPI I would get pretty good apk bloat.

You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.

I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.

It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.

Taken from the link below

  • ldpi: Low-density screens; approximately 120dpi.
  • mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
  • hdpi: High-density screens; approximately 240dpi.
  • xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
  • nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
  • tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. This qualifier was introduced with API level 13.

List taken from this dev link for more info.

This is the approach I have used on many apps in my professional career including ones for Google & the BBC and not had issues.

like image 58
Dori Avatar answered Oct 03 '22 01:10

Dori