Eclipse 格式化代码块快捷键:Ctrl+Shift+F
java---code style ---formatter
首先新建一个,如zxm。因为eclipse自带的不能编辑
编辑,在tab的Line Wrapping设置 最大的line width 即可。默认为80.这样以后代码自动格式化时不会给换行了。
但对于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的一些配置及进行一些额外的操作: