Switched my eclipse project to Android studio. I was maintaining resources under drawable-mdpi folder only. Now in studio the preview of XML loads images correctly. However when I run the app in a device with resolution higher than mdpi the app crashes, shows error inflating binary XML. After a long analysis I found the issue that the device was trying to load images from its corresponding density folder which is not available. So I created the folder drawable-xhdpi and put images in that folder. Now the app works fine. Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.

- 19,027
- 9
- 49
- 63

- 19
- 1
-
you have to create – Karthi Aug 24 '16 at 06:15
-
3you can keep them only in drawable folder, dont mention density it will pick from there. But for better resolution it is recommended to create images accrdingly. – Abdul Khalid Aug 24 '16 at 06:22
-
Abdul Khalid's answer exactly right. – Vasant Aug 24 '16 at 06:24
-
In Android Studio project you image in res/drawable folder showing as imageName.png(mdpi) ? – Ramit Aug 24 '16 at 08:06
3 Answers
you don't need to add all images to each difference size folder but depending the size of the image you might need to add images to different folders.
simple example is this can occour once you add high res/size images in normal drawble folder
Skipped 100 frames! The application may be doing too much work on its main thread.
This might not crash your app but will make it's performance down.
and
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 : https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
Do we need to add all images with different dpi to Android Apps
-
Even though I had images in the hdpi folder, In the xhdpi supported device the app crashes. The app cant find image from hdpi. – Suhail Ali M Aug 24 '16 at 06:41
-
-
android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) Here relative layout is the parent layout. There is a background image set to this layout which is present in hdpi drawable folder only. – Suhail Ali M Aug 24 '16 at 10:33
you have to add "drawable-hdpi" resource directory and paste all the hdpi resources there because currently 70% android devices supports hdpi resolution images.
if you only maintain the hdpi, then it is also ok. android manages all remaining resouces from hdpi resouce directory.

- 331
- 3
- 12
-
1Then what will I do for xhdpi. I am ready to maintain one folder. Let it be xhdpi. But can't maintain 5 at a time. My question is why studio doesn't pick images from other drawable folder. Is there any anything I have to do with Gradle – Suhail Ali M Aug 24 '16 at 06:17
Android application resource directories provide different layout designs for different screen sizes and different drawables. These different drawables are used by android to support a major range of all the android devices present out there. It's a standard practice to put your resources considering these densities. Coming back to your query:
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
For your case,In order to maintain this you could create a drawable with nodpi and put your all resources there. nodpi focus resources for all densities.Your resources should be density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
Hope this will clear your doubts, for more insight you can also look this.

- 1,162
- 6
- 20
-
Thanks for the update. I am still wondering why my app cant fetch and scale images from other resolution folders. When I run the app in a device which supports xhdpi even though hdpi folder contains all images the app crashes. Why its not picking up images from hdpi. – Suhail Ali M Aug 24 '16 at 06:37
-
@SuhailAliM Lemme rectify you here, Though you have xhdpi folder but what matter is are those images present in the xhdpi have density of 320dpi? Unless this android will fetch out for your expected behavior. – Anurag Aug 24 '16 at 06:43