Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With default resources in the drawable folder (MDPI sized) what's the point of the drawable-mdpi folder?

I've a full set of images at the various different pixel densities, and I need to put bitmap resources into the drawables folder (at MDPI) to use as default resources (to prevent crashing on pixel density devices I've not catered to, e.g. xhdpi), but that means duplicating the resources in the drawable-mdpi into the drawable folder.

So as duplication is clearly bad, I'm wondering whether I should just delete the drawable-mdpi folder, and keep my MDPI resources in the (default) drawable folder

Or am I missing something?

like image 471
Ollie C Avatar asked Mar 14 '11 17:03

Ollie C


People also ask

What will be in the drawable folder of android?

In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.

What is the preferred image format for the Drawables?

Supported file types are PNG (preferred), JPG (acceptable), and GIF (discouraged).

How do I make a drawable Xxhdpi folder?

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 .

How do I add a photo to a drawable folder?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.


2 Answers

You don't need to duplicate your resources. A good practice is to do the following: - Put all non image-based drawables inside res/drawable/ (for instance all your XML drawables) - Put all image-based drawables (images and 9-patches) inside res/drawable-mdpi, res/drawable-hdpi, etc.

like image 125
Romain Guy Avatar answered Oct 30 '22 12:10

Romain Guy


All I would say, is that obviously Romain guy is correct about using drawables to keep xml files in and then moving image resources into the relevant mdpi, hdpi and ldpi folders, the only time I'd go against this is when you wish to target 1.5 devices.

The reason for this is that because 1.5 has no recognition for the -hdpi, -mdpi and -ldpi tags, it ignores them and picks resources (seemingly randomly) from each folder, so instead you have to add the following flag -hdpi-v4, -mdpi-v4, -ldpi-v4, this will then make those folders accessible by 1.6+ versions of Android forcing 1.5 to only see the drawable folder, at which point you need to have all your resources in drawable, which then removes the need to have the drawable-mdpi folder.

However, since 1.5 is getting on a bit and such few devices have it, it makes more sense to target 1.6+ and ignore this complication.

like image 1
Matt Gaunt Avatar answered Oct 30 '22 11:10

Matt Gaunt