Android Studio: Drawable Folder: How to put Images for Multiple dpi?

156,290

Solution 1

The standard procedures are:

  1. Choose Project > app > scr > main
  2. Right click "res", choose "New" and choose "Android resource directory" Step 2
  3. In the opened dialog, at Resource Type choose "drawable" Step 3
  4. In the list Available qualifier choose Density, then click the right arrow at the middle. Step 4
  5. Choose the Density that you like then press OK Step 5

Solution 2

There are two ways of doing it.

1.Right click on drawable New->Image Asset-> select your highest resolution image rest will be created automatically. once you finish you can see different resolution inside drawable folder

  1. The way you want. on the project Explorer window you see a dropdown as Android. Click it change to project.

Now yourprojectname->app->src->main->res->

Aila You can see your drawable folders with hdpi mdpi etc.

Solution 3

You don't create subfolders of the drawable folder but rather 'sibling' folders next to it under the /res folder for the different screen densities or screen sizes. The /drawable folder (without any dimension) is mostly used for drawables that don't relate to any screen sizes like selectors.

See this screenshot (use the name drawable-hdpi instead of mipmap-hdpi):

enter image description here

Solution 4

The easiest way I have found to have the proper "directory" structure appear under the drawable folder for my icons is this:

  1. Right click "Drawable"
  2. Click on "New", then "Image Asset"
  3. Change "Asset Type" to "Action Bar and Tab Icons"
  4. For "Foreground" choose "ClipArt"
  5. For "Clipart" click and "Choose" button and pick any icon
  6. For "Resource Name" type in you icon file name

Now the pseudo-directories have been created for you under the Drawable folder in the Android view. Open up the true directories on your file system "main/res/drawable-xxhdpi", "main/res/drawable-xhdpi" and replace the icons in each folder with your own of the proper density.

Solution 5

Simply go to project Explorer and change your View from Android to project from drop Down and you are good to go.There you can simply create folder like we do in Eclipse. And in android project view it is hidden but when you switch to project. You can create folder like drawable-hdpi,drawable-xhdpi.

enter image description here

Share:
156,290
praveen
Author by

praveen

Updated on August 14, 2021

Comments

  • praveen
    praveen over 2 years

    Hi as per android documentation the drawable folder needs to have multiple sub-directories for images of different dpis. However in Android Studio creating any sub directory in the drawable folder causes it to fail to detect any images at all. On the other hand if an image is placed directly in the drawable folder it gets detected and becomes available for use view R.drawable.ImageName. In this case how do we use different dpi images for the same ImageName?

  • kalyan pvs
    kalyan pvs about 9 years
    mipmap is only for icons for more check this stackoverflow.com/questions/28065267/mipmap-vs-drawable-fold‌​ers
  • praveen
    praveen about 9 years
    Yes we need Sibling Folders not the folders below the drawable folders. This is the detail I missed in the documentation. Thanks for pointing out @Ascorbin
  • G_V
    G_V almost 9 years
    This is so utterly and completely confusing, I wish I was still doing it manually. In the android file explorer I have drawable-hdpi and all those folders but I can't access them even though they have images in them I never placed there. In my OS wm I don't have any of these, so I can't check the sizes and my app is slow so I doubt it's working properly. I'm just going to have to manually look up the pixel per dpi per folder and then scale everything and hope that fixes it instead of loading the broken hidden folders. Good thing programmers don't have anything better to do than resizing fml
  • fweigl
    fweigl almost 9 years
    @G_V You might be in the 'android' mode of displaying files in Android Studio. Set it to 'project' and you'll probably be happy :) stackoverflow.com/questions/29458189/…
  • Paul McCarthy
    Paul McCarthy about 8 years
    This is the only answer that suggests how to access the images and it has been marked down. None of the answers here say how and image is chosen. It appears to happen by magic.
  • Paul McCarthy
    Paul McCarthy about 8 years
    I can see an image in hdpi and mdpi but when I preview all resolutions in the designer all I see is the hdpi image. How do I dell andriod "Display image I on resolution R"
  • Fattie
    Fattie over 7 years
    Even after doing this, I still cannot access the images!!
  • Karan Thakkar
    Karan Thakkar almost 7 years
    Amazing answer. Thanks!
  • temirbek
    temirbek over 6 years
    first way only adds icons
  • Sumukh Bhandarkar
    Sumukh Bhandarkar over 6 years
    The method to add a folder is correct. I appreciate that. However to access the folder, you will have to change the Project Structure View from Android to Project. Here navigate to res->xxhdpi @Fattie
  • iamkdblue
    iamkdblue almost 6 years
    @Fattie you can access by @drawable/your_file_name , it will automatically pick your file from drawable-xxxhdpi (in my case).
  • Ariel Antonio Fundora
    Ariel Antonio Fundora almost 6 years
    Thanks, your way is easy and quickly.
  • Sandeep Insan
    Sandeep Insan over 5 years
    This will work only if you have the folder already exists in drawable.
  • Yash
    Yash almost 4 years
    There is no drawable resource type to create drawable directory(atleast in latest version in windows)