Eclipse 格式化代码块快捷键:Ctrl+Shift+F
但对于XML文件来说有时格式化后,一个控件的配置属性全都挤在一行,阅读和修改起来都很不方便。
而我们希望最佳的格式化效果如下,控件的每个属性配置占一行方便阅读修改,没有子元素的控件直接使用 /> 关闭:
<?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>
1)修改Eclipse的XML格式化配置
勾选 “Split multiple attributes each on a new line” 即可,如下图所示:
2)压缩节点的声明方式