Eclipse格式化设置。。。
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>
为了达到上述的格式化效果,需要修改Eclipse的一些配置及进行一些额外的操作:
1)修改Eclipse的XML格式化配置
这一步的配置是使格式化的效果为控件的每个属性配置占一行。进入 Window/Preferences,展开到 XML/XML Files/Editor,
勾选 “Split multiple attributes each on a new line” 即可,如下图所示:
2)压缩节点的声明方式
这步的目的是将没有子节点的元素的声明方式进行压缩,如将
“<TextView
...></TextView>” 转化为
“<TextView .../>”。