Android Studio 布局文件格式化代码

来源:互联网 发布:南京大学软件工程技术 编辑:程序博客网 时间:2024/04/29 23:47

Android Studio 布局文件格式化代码

原本布局文件的代码是下面的样子:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.chenql.changeappicon.MainActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!"/></RelativeLayout>

现在Android 建议布局文件结束标签要换行,即期望格式如下:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.chenql.changeappicon.MainActivity"    >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!"        /></RelativeLayout>

进入Android Studio 设置界面,Editor -> Code Style -> XML -> Android -> Layout Files :勾选”Insert line breaks after last attribute”,即在最后一个属性后插入换行符,最后点击”Apply” 应用修改,这样Layout XML 文件在格式化代码时闭合标签就会在下一行插入了。

这里写图片描述

写在最后:
对我这种三分钟热度的人来说,坚持写blog 果然任重而道远呀!
早就想知道怎么做这样子格式化代码了,却一直懒!今天才来查看设置怎么做的!

0 0