androidandroid-layoutandroid-shapeandroid-shapedrawable

Android - Is this mandatory to create each shape in separate xml file?


Let say i want these shapes in my project, like rectangle, ring and oval:

enter image description here

Which means i should have three xml files for each shape.

So, as far as i know we create separate xml file for each shape. Is this mandatory to create each shape in separate xml file? Is there any way to create all needed shapes in one xml file and call each shape with the help of attribute name, id or something else which will help us to reduce the number of xml files?


Solution

  • To give you an answer : no, you have to have different files.

    But there are several different advantages to this : having 3 different files means that they are easier to re-use (in future, you can select to add ONE file to your new project and skip the others) and it's easier to modify (finding ONE file to edit is simpler than having to scroll through ,which could at that point be, 1000 shapes). Even though this is potentially debatable and having one file also has its own advantages, the answer is still : you have to create separate files