XML file formatting configuration for Android projects in eclipse

Source: Internet
Author: User
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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.