Ctrl+Shift+f (Code Formatting) is not working properly in Eclipse Helios

三世轮回 提交于 2020-01-06 18:02:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!