Android Studio: Drawable Folder: How to Put Images for Multiple Dpi

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

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

Android Studio drawable folders

If you don't see a drawable folder for the DPI that you need, you can create it yourself. There's nothing magical about it; it's just a folder which needs to have the correct name.

How to add an image to the drawable folder in Android Studio?

For Android Studio 1.5:

  1. Right click on res -> new -> Image Asset
  2. On Asset type choose Action Bar and Tab Icons
  3. Choose the image path
  4. Give your image a name in Resource name
  5. Next->Finish

Update for Android Studio 2.2:

  1. Right click on res -> new -> Image Asset

  2. On Icon Type choose Action Bar and Tab Icons

  3. On Asset type choose Image

  4. On Path choose your image path

  5. Next->Finish

The image will be saved in the /res/drawable folder.

Warning!
If you choose to use images other than icons in SVG or PNG be aware that it could turn grey if the image is not transparent. You can find an answer in comments for this problem but none of these are verified by me because I never encountered this problem. I suggest you to use icons from here: Material icons

Android add multiple pictures to drawable res folder

I use below code to get drawables. hope it will work for you. no need of .png file extention. thats what you did wrong. Also use getResources() method before calling getIdentifier.

String mDrawableName = user.getNat().toLowerCase(); //image or icon name. not need extention .png
int resourceId = getResources().getIdentifier(mDrawableName, "drawable", getPackageName()); // or use context.getResources(). If you use fragments, use getActivity().
Drawable drawable = getResources().getDrawable(resourceId);
countryIcon.setImageDrawable(drawable );

Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image?

I was using "Android Asset Studio". Now I am using IconKitchen, the successor to the Android Asset Studio, and a great new way to make highly customizable app icons for Android, iOS, web, Windows, Linux and Mac.

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

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.

How to detect multiple resolutions images from a single drawable folder at android studio

Targeting specific resolutions is possible with resource directory qualifiers. For example you can create folder drawable-w320dp-h533dp-hdpi for 480px x 800px image on hdpi screen.

EDIT: Since you probably are using Android Studio, you can define the qualifiers in the dialog when you are creating new resource directory.



Related Topics



Leave a reply



Submit