问题
When I try to format code in Eclipse Helios, by pressing ctrl+shift+f, the code is getting formatted, but the results are very ugly. Two or three statements in one line, for example. Indentation is also very poor.
For ex: After formatting the code it looks like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/scannerbg">
<include android:id="@+id/headerLayout"
android:layout_alignParentTop="true" layout="@layout/headerlayout" />
<ListView android:layout_below="@id/headerLayout"
android:layout_height="fill_parent" android:layout_marginTop="5dp"
android:listSelector="@android:color/transparent" android:id="@+id/listView"
android:layout_width="fill_parent">
</ListView>
</RelativeLayout>
As you can see in ListView
, two to three statements are there in single line.
Can anyone offer a solution to this?
回答1:
In Eclipse, from the Window menu select Preferences. Expand the Android node and then select the Editors subnode. On the right pane ensure the "Format XML files using the standard Android XML style.." (the first option) is checked, and maybe other option(s).
Ctrl+Shift+f and/or Ctrl+i should work as expected and give these result:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/scannerbg"
android:orientation="vertical" >
<include
android:id="@+id/headerLayout"
android:layout_alignParentTop="true"
layout="@layout/headerlayout" />
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/headerLayout"
android:layout_marginTop="5dp"
android:listSelector="@android:color/transparent" >
</ListView>
</RelativeLayout>
回答2:
Use ADT version 20 for perfect formatting.
来源:https://stackoverflow.com/questions/12176020/ctrlshiftf-code-formatting-is-not-working-properly-in-eclipse-helios