开发者

Android: How to organize project resources?

开发者 https://www.devze.com 2023-03-27 20:55 出处:网络
I\'m wondering what some good ways of organizing Android projects are. I\'m building a little recipe application and have already made dozens of layouts, drawable resources, menus, etc., not to mentio

I'm wondering what some good ways of organizing Android projects are. I'm building a little recipe application and have already made dozens of layouts, drawable resources, menus, etc., not to mention Java source code.

Android does not allow sub-folders for resources, so is there a way to organize them? Right now I'm trying to organize them through naming conventions (e.g. new_list_ingredient_edit) but I'm wondering if there is a better way, as the names will probably get pretty long and cumbersome.

Same thing with resources such as string values. As I understand it, I can create multiple resource files (e.g. strings_n开发者_如何学JAVAew_ingredient.xml, drawables_new_instructions.xml, etc.) but all my resources across files have still have to have unique names, which again is cumbersome.


Although android doesn't allow sub-folders for resources, it does for assets, but this is much more cumbersome to use.

A possible option would be to use a sql database with all of your strings, but this approach is probably too much work and more cumbersome anyway.

Your naming convention method is probably your best option. You could think of some of the seperated words as directories if you want, which should keep it organized enough.


user864684,

I normally try to use heirarchy in my naming. If it is a layout for dialog, i will start with dialog_sharing or something like that.

As for graphics, I will start with btn or bg or txt or ic_menu depending on what they are for. Other than that, you just get used to it as you dev more for Android.

Make sure you also have a support folder on your drive for your local resources. I mimic the android layout so i keep my graphics sorted in res/... on my local drive too. I keep the psd and graphic files there and then just copy the pngs to eclipse.

Hope this kinda of helps. There is no real standard but you will pick up a style.


Specifically with respect to organizing drawable resources, I would advise choosing names that describe the drawables structurally, not functionally.

For example, if you have a gray circle shape resource that you are using as a placeholder for an image, I would avoid naming it *image_placeholder*. Instead, I would call it *gray_circle_1*.

My advice comes from having had the experience on multiple occasions of having given things names like *image_placeholder*, forgetting what they actually contained, and then rewriting the same exact thing in a separate resource file without realizing it.

Don't do what I did.

0

精彩评论

暂无评论...
验证码 换一张
取 消