如何在Android Studio中重新格式化XML布局

问题描述 投票:0回答:2

在我的项目中,我在XML布局的设计表中创建了一些UI。但是,当我转到文本选项卡时,代码的格式不正确!

I selected

Reformat code from right click menu on XML

 but the code is still not properly formatted!

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:inputType="textPersonName" android:ems="10" android:id="@+id/nameTxt" android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp" android:hint="Name"/> </android.support.constraint.ConstraintLayout>
我如何改进我的上述代码?

对于Reformat代码
xml android-studio
2个回答
12
投票
Your XML File Code after use

Reformat Code

<EditText android:id="@+id/nameTxt" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:ems="10" android:hint="Name" android:inputType="textPersonName" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />

它与ctrl + alt +l

一起使用

或您只需单击菜单栏中的

代码,然后选择代码格式

enter image description hereandroid Studio XML代码方案 - 就像在此图片中 Change XML Code Scheme for "Default IDE" in Android Studio Preferences.


10
投票

在最近的Android Studio中,ShotCut是Ctrl + Alt + Enter inXML.

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.