I am developing a game for android an i’m working on the menu screen right now.
I am going to use my own drawables as a button, and I was just wondering if (and how) it is possible to pull individual drawables from different ares of a resource.
To say, I have the button overlay, a red button under-layer, and a grey under-layer, all on the same resource, and was wondering if I need to separate them into three distinct resources and use them, or can I pull from different areas of the resource?
It sounds like you want to use a technique that’s known as CSS Tiling. Android has no built-in support for the CSS feature where one can specify the bounds of an image resource and specify the X/Y direction of repetition.
However, between Android and Java a programmer can do pretty much anything they want to an existing Bitmap or one they’ve created on-the-fly. In Android it’s possible to “clamp” images so only a certain region of the image is rendered. I found an example linked in an answer at Center a bitmap and repeat the edge pixel. The technique used in the linked article resembles what you’re trying to do.
While it’s doable, it just isn’t as practical in Android as in CSS. For example, if you use a technique like above, and later need to change something in your resource image: you also have to manage the code that makes the resource work properly in your app. The alternative is having to manually “cut” the image (yes, as you suggest, into multiple resources) and this is probably better in the end. For example, if you need to make that resource a 9-PNG or perform other changes to it: your work is limited to Photoshop and doesn’t require any Java-writing, code-compilation, and probably requires less regression testing as a result.