The XML auto formatting in Eclipse ADT is currently not working properly.
When I am working on Android apps with big XML layout files in Eclipse ADT, the XML tends to get a little cluttered, and sometimes the many attributes ends up on one single line like this:
This makes reading the XML layout far more difficult than if they were all ligned up properly below each other.
Pressing Ctrl + Shift + F to auto format the XML, didn’t actually make it any better:
(Default XML formatting)
So here is how to fix this problem.
How to fix the XML auto formatting in Eclipse ADT
In Eclipse go to Window -> Preferences
Then in the Preferences, go to *XML -> XML Files -> Editor *
Check the box to Split multiple attributes each on new line
Then hit Ok, go to your XML file and try to format it again with Ctrl + Shift + F (or Right click -> Source -> Format).
Thats better! Now it works like it’s supposed to!
But even if the XML auto formatting now works, Eclipse does not clean up the XML tags.
Cleaning up the XML tags with “Cleanup Document”
If your XML tag looks like this:
You can Right click -> Source -> Cleanup Document to get this menu:
Hit Ok, and it will Compress empty element tags, so your XML will end up like this:
This trick makes reading and working with XML in Eclipse a lot better.
Tip: Notice that the Cleanup Document also does a Format Source for you, so you don’t have to.