简体   繁体   中英

drawable vs. drawable-ldpi/drawable-mdpi

All the Android docs mention the "drawable" directory. However, when I create an Android project in Eclipse, it doesn't create a "/res/drawable" directory, but it does create "/res/drawable-ldpi" and "/res/drawable-mdpi". I imagine those have something to do with pixel resolution, but what's exactly going on here? When I've stepped through the tutorials, I've manually created a "drawable" directory and put my resources in there, but did I need to? Do references to "/res/drawable/" work if only "drawable-{l|m}dpi" are present?

I believe this was added in Android 1.6. It's all explained here: http://developer.android.com/guide/practices/screens_support.html

Yes, you need to make a default /res/drawable directory in Eclipse.

If you want to use the -hdpi/-mdpi/-ldpi folders, then you need to make separate xml layouts to refer to them.

http://developer.android.com/guide/practices/screens_support.html

I assume it has something to do with how you generated the Android project. Typically mine creates an hdpi, mdpi, and ldpi folder. Basically, "drawable" is the default. If you have all of your resources in the hdpi folder, and try to run it on an ldpi device, I believe you will get an exception of some kind (I have not tested this, but I believe this to be the case). A detailed explanation of what happens without default resources is explained here .

You should keep a default collection of resources in the main "drawable" folder (that yes, you may have to create manually) just to be on the safe side, and to ensure compatibility with older versions of Android. Android will check the specific density folders first, but will roll back to the default drawable folder if it cannot find that specific resource in that density.

The lastest SDK's create a lot of drawable folders for you when a new app is created for various screen densities, although oddly the default 'drawable' folder mentioned in the docs has never been created for me by default.

If you duplicate and resize your graphic resources for all six density folders currently created by default, from drawable-ldpi to drawable-xxxhdpi, your app size will be bloated for a heavy graphics app, not to mention other issues cropping up like heap size crashes (they should provide different folders for different device heap sizes).

Currently I put all my graphics in the drawable-hdpi folder, except for copies of the launcher icon for higher resolutions in the xhdpi, xxhdpi, and xxxhdpi folders. I don't put anything in the mdpi and ldpi folders, and in fact have deleted those folders to keep the app clean. I could also have renamed the drawable-hdpi to just drawable, but have kept the default name as it acts as the default folder in this case anyway.

In this answer , @RomainGuy mentioned that you should keep appropriate images to their respective folders (mdpi, xhdpi), and other sources like .xml files for drawables in your drawable folder.

For example,
if you will be using a hdpi device, while you have not put any image in hdpi folder, it will not crash; it will instead resize image from its next best fit folder (ie mdpi) and will expand the image.

Hdpi, mdpi and ldpi qualifiers were added in Android 1.6. If you're going to support Android 1.5 you should put all you medium-dpi drawables into the default drawable directory.

You can read about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM