是否可以在Android Studio中修改XML布局模板,以便命名空间和属性显示在不同的行上?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
默认模板(下方)在单独的行中显示每个属性(不包括命名空间),但这些换行符不会转换为生成的资源文件。
答案 0 :(得分:0)
问题在于Android Studio不尊重XML模板中的换行符。
Keep line breaks
设置&gt;编辑&gt;代码风格&gt; XML&gt;其他(标签)
设置&gt;编辑&gt;文件和代码模板&gt;其他(标签)
XML布局现在将在不同的行上生成命名空间和属性,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
相关的代码模板是:
layoutResourceFile.xml
layoutResourceFile_vertical.xml
确保Keep line breaks
在后续运行时仍然存在
Android Studio,请确保修改Project
计划而不是
Default
计划。