XML file formatting configuration for Android projects in eclipse
Using ADT in eclipse to develop Android is very convenient, but it is not satisfactory, for example, the formatting Effect of XML files is not ideal. By default, the visual interface layout of the ADT is used. In the automatically generated XML file, the configuration of a control is fully squeezed onto a row (as shown in the following figure), which is inconvenient to read and modify.
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout...>
<Textview Android: Id = "@ + ID/textview01" Android: layout_width = "wrap_content"...> </textview>
</Linearlayout>
I hope the best formatting effect is as follows. Each property configuration of the control occupies one line for easy reading and modification. controls without child elements can be directly used/> disabled:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Textview
Android: Id = "@ + ID/textview01"
Android: text = "some content"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
</Linearlayout>
To achieve the preceding formatting effect, you need to modify some eclipse configurations and perform some additional operations:
1) modify the XML formatting configuration of eclipse In this step, the formatting result is that each property configuration of the control occupies one row. Go to window/preferences and expand to XML/XML files/Editor, Select "split multiple attributes each on a new line", as shown in:
After this configuration, each time the shortcut key Ctrl + Shift + F is used for formatting, each attribute configuration occupies one row.
2) compression node declaration method The purpose of this step is to compress the declaration method of elements without subnodes, such as "<textview...> </textview> "to" <textview... /> ". Right-click a blank area in the XML file and choose "Source/cleanup document...", as shown in:
The following page is displayed:
Select compress empty element tags and click OK.For convenience, you can add a shortcut key for this operation, enter window/preferences, and expand to General/keys, such as configuring your favorite shortcut key: