Create folder in drawable - android

Is it possible to create our own folder in drawable and put all my images in that folder as:
"drawable\Myimages\p.png.."
If it possible than how can i use this images in my activity..gnerally we use "R.drawablw.p" but now how that can be written because now my images is in drawable\Myimages directory
please suggest me..
with regards
Anshuman

No, you can't create your own file hierarchy in drawable directory.
But you can see in http://developer.android.com/guide/topics/resources/providing-resources.html:
However, if you need access to original file names and file hierarchy,
you might consider saving some resources in the assets/ directory
(instead of res/raw/). Files in assets/ are not given a resource ID,
so you can read them only using AssetManager.
If you have very many resources, it can be useful for you.

No, the resources mechanism doesn't support subfolders in the drawable directory.You can't used.

Related

Saving to drawable folder programmatically in Android

I'm looking to have a user select an image from the gallery, and have this file saved as a permanent drawable resource when they open the app at a later time. Is this possible?
I mean as an object in the actual drawable folder.
No, it's not possible. "The drawable folder" doesn't exist as a file system folder at runtime - it's part of your (read-only) binary .apk file.
You could instead save the image at internal folder and/or define a preference string.
Check this old answer https://stackoverflow.com/a/3374138/4618976

difference between assets folder and res/xml [duplicate]

This question already has answers here:
Difference between /res and /assets directories
(8 answers)
Closed 9 years ago.
in this tutorial for "learning to parse XML data in your Android App" the author puts his XML file into the assets folder. But in other tutorials they recommend to use res/xml.
None of them explains why they took the folder they use.
What is the difference between those two folders? What is best practice? Is there a difference in performance?
The res folder is used to put authorized resources files type, like layout(xml), drawable (png, jpg, xml), raw (mp3, ogg), etc... In the assets folder, you can put all files types you want (txt, avi, png, docx, xyz, ext, asm, ....).
Check this : Android Projects Structure
1) assets/
This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.
2) res/
Contains application resources, such as drawable files, layout files, and string values. See Application Resources for more information.
anim/
For XML files that are compiled into animation objects. See the Animation resource type.
color/
For XML files that describe colors. See the Color Values resource type.
drawable/
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.
layout/
XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.
menu/
For XML files that define application menus. See the Menus resource type.
raw/
For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.
values/
For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.
xml/
For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata. See Application Resources for more information about configuring these application components.
The difference between "resources" and "assets" isn't much on the surface, but in general, you'll use resources to store your external content much more often than you'll use assets. The real difference is that anything placed in the resources directory will be easily accessible from your application from the R class, which is compiled by Android. Whereas, anything placed in the assets directory will maintain its raw file format and, in order to read it, you must use the AssetManager to read the file as a stream of bytes. So keeping files and data in resources (res/) makes them easily accessible.
For details you can see following links :
Link1,
Link2

HorizontalScrollView Getting Images from /drawable folder

I am using HorizontalScrollView in order to create some Gallery-like option and right now I am getting the images from an folder in the external drive. But I figured that I don't need, also shouldn't do that since the images I wanted to show is predetermined images. So I will simply change the directory to the drawable folder but I am not sure which path to go. So right now I am getting the directory with this:
String path1= Environment.getExternalStorageDirectory().getAbsolutePath();
I found two more methods for directory retrieval but I am not sure which one to use.
String path2 = Environment.getDataDirectory().getAbsolutePath();
String path3= Environment.getRootDirectory().getAbsolutePath();
First one returns "/mnt/sdcard", second returns "/data", third one "/system".
Which one should I use in order to reach /drawable folder inside this way?
Which one should I use in order to reach /drawable folder inside this way?
None of them. Those are all for files on the filesystem. Drawable resources are not files on the filesystem.
Use getResources().getDrawable() to retrieve a Drawable given its ID (e.g., R.drawable.foo).

Android XML says image is not found in drawable folder?

I have this code:
android:drawable="#pickuptools.png"
the picture is called pickuptools.png and is inside the folder drawable-xhdpi.
I have tried #drawable-xhdpi/pickuptools.png, pickuptools without the file extension, and many more.
I can't find the picture through the XML.
The XML is located inside the drawable-xhdpi folder.
What am I doing wrong?
Use:
android:drawable="#drawable/picuptools"
You don't need to use #drawable-xhdpi or something. For any resources , you should use resource type(In your case its drawable) and name of the resource.
For further reference, check out this Android page on how to access Resources.

How to create a new folder inside the drawable folder and reference an image from it?

I am working on an ANDROID project where I have a lot of images and I want to organize it.
So I need to create folder inside the drawable folder.
But I don't know how to reference it in my program.
For eg: I have an image named "image.png" and I want to place it in drawable/myicons/image.png
or anywhere inside the res folder.
This is duplicate question
You can not create folder inside drawable
the resources mechanism doesn't support subfolders in the drawable directory
However you can use the assets folder and have sub directories in there and load images that way.

Categories

Resources