I have a large number of images in diffident folder. Can I place these folder in 'drawable' folder or there is any other pattern to add sub-folders in 'drawables'.
-
You can create sub folders.. but you cannot access them via "R.drawable.subfoldername.drawablename".. You can only access it by "R.drawable.drawablename". – mudit Sep 20 '12 at 05:09
-
2duplicate question http://stackoverflow.com/questions/1077357/can-the-android-drawable-directory-contain-subdirectories – Dinesh Anuruddha Sep 20 '12 at 05:09
2 Answers
No, the resources mechanism doesn't support subfolders in the drawable directory, so yes - you need to keep that hierarchy flat.
However you can use the assets folder and have sub directories in there and load images that way.
Sample Code
InputStream is = null;
try {
is = this.getResources().getAssets().open("test/sample.png");
} catch (IOException e) {
;
}
image = BitmapFactory.decodeStream(is);

- 56,621
- 29
- 151
- 198
By the structure of Android, we can place the images under drawable folders only. We have the choice to create subfolder, but unable to access them. Depends upon the density of the images we can place images inside the relevant folder: see below: The folder names need to be :
/drawable-ldpi For low density screens
/drawable-mdpi For medium density screens
/drawable-hdpi For high resolution screens
/drawable-xhdpi For extra high resolution screens
/drawable should be reserved for assets that you don't either care which device or for xml drawable assets
Then on top of that you can provide different resources based on configuration by using config qualifiers, you can read all about it here http://developer.android.com/guide/topics/resources/providing-resources.html
for instance, you can have high resolution assets for landscape with a folder
/drawable-land-hdpi
Hope that helps