4

If I wanted to put a bunch of images in a folder structure, e.g.. I’m building a beach app and each beach is displayed via my beach detail activity depending on the beach selected from my beach list. I then want to display five images from that particular beach. Each beach will have a folder with a name that corresponds to the _id of the beach and then five images in that folder, image1.jpg, image2.jpg… image5.jpg. should I put the folders and images in the /res/raw folder or the /assets folder for the best/easiest way to go.

Cheers,

Mike.

2 Answers2

7

Assets will allow you to create subdirectories (group files in directories) note that they have no name restrictions however you can only access it via Assets Manager which contains list() for listing files under a given directory and open() for obtaining a file's InputStream.

resources instead, allow you to access the files in the folders but you cannot create subfolders, moreover you must place the files in the right place so bitmaps go in /res/drawable, layout xmls in /res/layout and so on. Resouces are easy to access for other parts of your code since they have an identifier. Since you want to use the res/raw folder that means you cannot create a subfolder in it and that your images won't be compressed, so putting them without compress and considering they will be a lot of images then you app will be a bit heavy.

Here is two links that you might find helpfull: WiseAndroid and Providing Resources - Dev Guide

Basic
  • 26,321
  • 24
  • 115
  • 201
Raykud
  • 2,488
  • 3
  • 21
  • 41
  • Heavy, exactly and why they’re optional. I can optionally have them viewed via the net in a browser, but there is no internet access at most of the beaches. I have /res/raw working fine, you access it the same way as drawable, R.raw.imagename as there is a reference to them in R.java file. I guess for this app I can use the raw folder for the images only but wouldn’t it be better to put them in the assets in a more structured folder/file way, remembering they are an optional download??? –  Dec 07 '11 at 23:44
  • you can use the raw folder since its easier to handle, but if you really must have them in folders you will have to use assets. I would recommend using the raw folder. – Raykud Dec 08 '11 at 00:03
0

When adding images to your application you should place them in "res/drawable". That folder is for images that are not specific to any dpi level. For best results you should have three sizes of each image and place them in their respective dpi folders like "res/drawable-hdpi" for hi res images. This is a good section of the docs to read for resources and device compatibility.

Bobbake4
  • 24,509
  • 9
  • 59
  • 94
  • 2
    I have 97 beaches and five images for each so 485 images, I want them to be an optional download after the app is installed. I then want a button in the app that allows the user to download an update the images anytime if they want to, so I don’t think the drawable folder is the right place to put them. –  Dec 07 '11 at 22:53
  • There is one problem with this; even if you use the 'drawable' folder instead of the 'drawable-whateverDPI' folder, android will be doing some auto resizing/scaling of the image. This really can screw with you if you're drawing to a surfaceview and are trying to scale things yourself. – MacD Mar 26 '14 at 20:41
  • 1
    No, `drawable` is equivalent to `drawable-mdpi` and you don't want to put large images there as they'll be scaled up on `hdpi` and above. The folder you're looking for is `drawable-nodpi`. – Daniel Apr 29 '14 at 15:10