Ctrl+Shift+f (formato de código) no funciona correctamente en Eclipse Helios

When I try to format code in Eclipse Helios, by pressing ctrl+cambio+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>

Como puedes ver en ListView, two to three statements are there in single line.

¿Alguien puede ofrecer una solución a esto?

preguntado el 29 de agosto de 12 a las 11:08

I also fatch this problem. so i use indigo. -

No, but I have another m/c with Eclipse Helios only, but it works on that m/c without any problem. -

Yo removería android tag from this question. It has nothing to do with it.. -

I kept that tag, just to get attention from multiple users. -

2 Respuestas

In Eclipse, from the Ventana menú de selección Preferencias. Ampliar la Android node and then select the Editores 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+cambio+f y/o 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> 

Respondido 30 ago 12, 12:08

I could not found "Allow single attributes to appear on the same line as their elements" under Editors tab. - Shrikant Ballal

I quickly edited my answer when I realized the big typo while at same time you were reading it ;-) - aladino q

Oh sorry, but I could not found this "Format XML files using the standard Android XML style" also. There is nothing like this in Editors tab - Shrikant Ballal

Just below the "General" node in the Preferences, you should have an "Android" node for Android SDK settings. Is the Android plugin for eclipse properly installed? - aladino q

There is only single checkBox asking "Autmatically format the xml edited by the visual layout editor". - Shrikant Ballal

Use ADT version 20 for perfect formatting.

Respondido 29 ago 12, 20:08

check the eclipse Helios minor version also. it should be SR2 - Shrenik

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.