0
点赞
收藏
分享

微信扫一扫

强迫症 之 Android Studio 格式化 XML


LZ-Says:人呐,最可怕的便是,突然某天转身,却发现曾经以为的熟悉,却是那么陌生。

今天撸码的时候,突然发现格式化 XML 不管用了,而不格式化看的很湿别扭:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent" android:padding="15dp"
android:layout_height="match_parent"
tools:context=".moudle.MainActivity">

<Button android:id="@+id/btn_baidu"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="百度地图基本操作"/>

<Button android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/btn_baidu"
android:id="@+id/btn_google"
android:textAllCaps="false" android:layout_height="wrap_content" android:text="Google Map"/>

</android.support.constraint.ConstraintLayout>
</layout>

找了半天,才发现 Android Studio 默认提供一套标准,我们只需要打开即可,如下图所示:

强迫症 之 Android Studio 格式化 XML_格式化

这里需要注意俩点:

  • Scheme 选择 Default 即可(当然也可以自己设置);
  • 记得勾选 “Use custom formatting settings for Android XML files”。

快捷键:option + command + L,格式化效果如下:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:padding="15dp"
android:layout_height="match_parent"
tools:context=".moudle.MainActivity">

<Button
android:id="@+id/btn_baidu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="百度地图基本操作"/>

<Button
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/btn_baidu"
android:id="@+id/btn_google"
android:textAllCaps="false"
android:layout_height="wrap_content"
android:text="Google Map"/>

</android.support.constraint.ConstraintLayout>
</layout>

瞬间感觉爽了很多,有木有~

当然,动手能力强的小伙伴可以选择 Arrangement 自己手动添加规则:

强迫症 之 Android Studio 格式化 XML_xml_02

个人公众号

不定期发布博文,最近有点忙,感谢老铁理解,欢迎关注~



强迫症 之 Android Studio 格式化 XML_android_03


举报

相关推荐

0 条评论