How to categorize images in the drawable folder? - android

I have a lot of images and I want to classify them in the drawable folder in Android Studio for easy access, is it possible?

Not possible. The only way to sort your drawable resources is by renaming them, usually with prefixes (i.e. ic_ for icons).

You can't put them in folders. However, you can control the name of them to find them easier. For example, if I have buttons coded with shapes, etc, I will name these button_name. This way, it all of my buttons are there for me to view. If I have a few minutes in a certain activity, I will do something like results_, and then all of my results images are there. Hopefully they makes sense and helps.

Related

Android Studio: Is is possible to set default drawable folder?

I am having a rather annoying scenario where I work with a lot of drawable shapes, many of which are slightly changed variants of others. The annoying thing is, when I paste the drawable, it automatically defaults to a random resource folder. See bellow photo. I want it to go directly to the standard drawable folder, not some other density drawable folders without having to manually change the folder every single time.
Is this even possible?
You can change the View from Android to Project if you are copying & pasting multiple images in a row. You can simply paste it to the drawable folder.

Shall I put 9-Patch Image in different drawable for different screen size or i can place it only one time in drawable for different screen size?

I have one 9 patch image but i don't know that where i have to put it. only one time in Drawable folder or i have make different folder ( like mdpi,hdpi etc) in drawable for supporting different screen resolution.can anybody suggest me.thanks
Nine Patch images are mainly used to reduce the number of images. So if you are using nine patch, there is no need to use it in different folder we can use it drawable folder alone. This will reduce the number of resources used in the project, which will obviously reduce the apk size too, etc...
Hope this is helpful :)
Both drawable/ and drawable-*dpi/ work.
But I put all drawable *.xml files in drawable/, and all png/webp/jpg files in drawable-*dpi/, which makes the folder cleaner.
As u may use different *.9.png for different screen resolution respectively, drawable-*dpi/ may be a better choice.
Hope it helps.

What is the best practise to use with default drawables?

Having a specialized folder for default drawable ("drawable" with no screen size extension) would be more intuitive and self explanatory, making it easier to locate files. But will it cause logical errors in runtime?
What is the convention here? do most developers put default drawables in one of the screen-size-specific folders (and if so, which one?) or do most developers create a non-specific "drawable" folder?
In fact you should put it in drawable-nodpi as explained Here
It doesn't cause problems. Android looks in the "drawable" folder first, and then looks at any other folder as an override.

Android state file does not find dpi dependent drawable

I have a state file for buttons which worked fine until I put drawables into res/drawable-mdpi.
I had only drawable in res/drawable-hdpi but I want the app to work on all displays.
The state file is placed in res/drawable as I read it on some websites.
That way it is also done by google with the standard drawables but Ecplise keeps telling me that it can't find drawable with value #drawable/button_normal.
The drawables are definitely at their places.
So what am I doing wrong here?
Ok...there was nothing wrong with the code, drawables were not ok.
I made them again, 9-patched them and voilĂ : no comments by eclipse.
Sorry for wasting place for this.
make a folder drawable inside res and put ya pics into that folder. and you can refer to them as
android:background="#drawable/oscar"

Android button state files

The docs say to put XML state files for buttons in "the" "drawable" folder - which one of at least three?! (Putting it in res/drawable gives an out of sync filesystem error and putting it in each of the drawable-*dpi where * is l, m, h is an error too.)
res/drawable is ok and default.
The "fs out of sync" is probably from your IDE when you put the files e.g. via command line or into the folder. IDEs usually try to remember the state of files and report external changes this way. Try issuing a "refresh" command in the IDE.
res/drawable is a fallback that is taken if you do not provide more specific images in res/drawable-*dpi or also some orientation counterparts.
Have a look at the docs:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
drawable-nodpi is a special directory for files you don't want scaled, which makes no sense at all for buttons, as you want buttons to scale according to screen size/dpi.
You should use res/drawable for your XML state list drawables. If you get the "out of sync filesystem" error just refresh the Eclipse project (select it in the projects pane and hit F5).
XML state lists are (in most cases) not DPI-independent. However, their content will not change across different DPI environments. Basically, this means that if you reference a raw drawable called, for example, #drawable/btn_pressed, from within a state list, Android will look for the appropriate file for that drawable, according to the environment (drawable-*dpi/btn_pressed.png).
As you can see, although the state list is the same on LDPI, MDPI and HDPI, the drawables referenced within it could change.
I propose drawable-nodpi because it works.
However this is not made obvious in the docs when it needs to be.
How to make something trivial complicated? Make it ambiguous.

Categories

Resources