简体   繁体   中英

Android: When is it appropriate to store images in the assets rather than the drawable folders?

I have a bunch of images that are common for all resolutions (currently I only support one resolution. There are reasons for this).

My question is, when is it appropriate to store images in the assets folder rather than the drawable folder?

If you want to access images by their original name, you better save images in the assets folder. Then, you can get them by using:

AssetManager:AssetManager am = getResources().getAssets();
try {
    InputStream is = am.open("image.png");
    // use the input stream as you need
} catch (IOException e) {
    e.printStackTrace();
}

I Hope this helps.

you can change the files in assets folder anytime you want and nothing will be effected (i mean the resources of your application by "nothing"). it may be useful to give the name of the image file as a parameter for example.

The difference between a raw resource in res/raw directory and an asset is that assets behave like a file system, they can be listed, iterated over, discovered, just like files while for raw resources, you need the resource ID.

From: http://mylifewithandroid.blogspot.it/2009/06/assets.html (emphasis mine)

Also you may use assets when you need to organize things using sub-folders.

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