Android Studio 在格式化时更改组件的顺序

标签 android android-studio format

<分区>

我在 android studio 中创建了一个简单的布局文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/NameEditText"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

当我按下 ALT+CTRL+L(重新格式化)时,android studio 将我的代码更改为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/NameEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>

您可能已经注意到,按钮的位置已从末尾更改为第一,编辑文本的位置已从代码开头更改为代码结尾!

你能告诉我这种行为是不是错误吗?如果不是错误,如何配置 android studio 使其正常运行?

最佳答案

文件 > 设置 > 编辑器 > 代码样式 > XML > 排列(选项卡)> 强制重新排列 => 从不

关于Android Studio 在格式化时更改组件的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58381806/

相关文章:

android - 如何使用 Kotlin 为 RecyclerView 创建上下文菜单

mysql - 这是什么日期格式? (从 Win32_PrintJob 选择 *)

format - Google Play的FT311D配件启动应用程序

android - 三星 Galaxy 平板电脑不允许将 float 输入到 "number"类型的输入中

android - 如何将社交身份验证库集成到我的 android studio 项目中

Android:给定原始图像的Uri,获取SD卡上图像的缩略图

android - 成功生成apk后运行python脚本

android - 如何通过单击更改整个应用程序的语言?

java - Android Studio 中支持的 @SuppressWarnings 值

windows - 为变量分配多个驱动器号