【问题标题】:Eclipse disorders an XML file after pressing Ctrl + Shift + F按 Ctrl + Shift + F 后 Eclipse 会破坏 XML 文件
【发布时间】:2013-04-26 12:13:41
【问题描述】:

Ctrl + Shift + F 在整理 java 或布局文件时做得很好。但是它是否会破坏以<selector xmlns:android="http://schemas.android.com/apk/res/android"> 开头的文件中的内容(例如)?

这就是我所拥有的。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><nine-patch android:src="@drawable/bg_list_row_pic" />
    </item>
    <item><nine-patch android:src="@drawable/bg_list_row_pic" />
    </item>

</selector>

这样会好很多。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <nine-patch android:src="@drawable/bg_list_row_pic" />
    </item>    
    <item>
        <nine-patch android:src="@drawable/bg_list_row_pic" />
    </item>

</selector>

我浏览了Window - Preferences - XML,但没有找到任何解决问题的方法。

添加。

如果我使用Format XML files using the standard Android XML...,我的布局文件中有以下内容,但包含&lt;selector&gt;&lt;item&gt;s 的文件看起来正常(请参阅此消息中的“这会更好”)。

它不适合我。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:layout_gravity="center"
    android:paddingLeft="@dimen/sixteenDp" android:paddingRight="@dimen/sixteenDp">

    <Button android:id="@+id/mainAct_btn_RunTest"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/sixteenDp" android:text="@string/run_test" />

    <Button android:id="@+id/mainAct_btn_ShowList"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_below="@id/mainAct_btn_RunTest" android:text="@string/show_list" />

</RelativeLayout>

这个布局文件适合我。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingLeft="@dimen/sixteenDp"
    android:paddingRight="@dimen/sixteenDp" >

    <Button
        android:id="@+id/mainAct_btn_RunTest"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/sixteenDp"
        android:text="@string/run_test" />

    <Button
        android:id="@+id/mainAct_btn_ShowList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/mainAct_btn_RunTest"
        android:text="@string/show_list" />

</RelativeLayout>

【问题讨论】:

    标签: android xml eclipse coding-style


    【解决方案1】:

    你可以试试这个。转到 Windows->Preferences->Android->Editors 并禁用第一行“Format XML files using the standard Android XML...”

    【讨论】:

    • 谢谢。它在这种特殊情况下有效,但如果我将它用于布局文件,文件将变得混乱
    • 你确定吗?我故意编辑了我的布局,当我按下 ctrl+shift+F 时它们都很好。你观察到什么病症,能发一下吗
    • 当然,默认的 xml 格式化程序不会重新排列 Androidy 的属性顺序。它只会格式化正确的间距和缩进。
    • > 你观察到什么乱七八糟的,能发一下吗@Neoh,我发了
    • 如果我是你,我会默认勾选“Format XML files using the standard Android XML...”,当涉及到包含 的 xml 时取消选中它。我知道,点击几下很麻烦,但直到谷歌解决了这个小问题,我认为这是你能做的最好的。
    猜你喜欢
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 2012-05-16
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多