Is it possible to modify the XML layout template in Android Studio so that the namespace and attributes appear on separate lines?
<?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>
The default template (below) shows each attribute (not including the namespace) on separate lines, but these line breaks don't translate to the generated resource file.
The problem is that Android Studio isn't respecting line breaks in the XML templates.
Keep line breaks
in
Settings > Editor > Code Style > XML > Other (tab)
Settings > Editor > File and Code Templates > Other (tab)
XML layouts will now generate the namespace and attributes on separate lines, like so:
<?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>
The relevant code templates are:
layoutResourceFile.xml
layoutResourceFile_vertical.xml
To ensure that Keep line breaks
persists on subsequent runs of
Android Studio, make sure to modify the Project
scheme rather than
the Default
scheme.