Thursday, January 27, 2011

Formatting Android Layout XML in Eclipse

Sometimes when you are editing Android Layouts in Eclipse, it makes more sense or is more convenient to change the actual xml content. The problem is, a lot of the time the xml is not pretty to look at. Lines of text often run off the screen and it is difficult to tell where one element begins and another ends.

Messy Android Layout XML
But fear not!

Eclipse has some handy auto-formatting tools. Press Ctrl+Shift+F to auto-format the selected file. Or from the menu, click Source->Format.

Formatting Menu Option

Now your file will be cleaned up and easier to edit.

Formatted Android Layout XML

If you have text selected, only the selected text will be formatted. If no Text is selected, the entire file will be formatted. And Auto-Format will work on your Java files too.

1 comment: