Possible Duplicate:
Best practices: Layouts on Android (Programmatic vs XML)
1) defining the layout in xml by adding standard view in layout.
2) Draw the required in the onDraw of an custom view
Good answer from Ollie C https://stackoverflow.com/a/9827887/603233:
The advantages of XML are:
1. Ability to use layout editors (Eclipse) 2. Easier to preview layouts 3. Possible to benefit from auto-localisation of layouts 4. Easily maintain different parallel layouts for difference devices (screens) 5. Can get a sense of the layout by looking at it (easier than code) 6. Easy to break layouts down into pieces (fragments, includes, etc) to remove duplication 7. Keeps a separation between the visual design, and the functionality behind it