相信在用studio寫布局xml的時候LinearLayout會報一些警告
Set android:baselineAligned="false" on this element for better performance less
在使用lint檢查時也會出現(xiàn)
Missing baselineAligned attribute
先來看baselineAligned這個屬性的字面意思baseline Aligned基線對齊
那和我們平時的開發(fā)有什么關(guān)系呢
出現(xiàn)此警告時大多(其他還沒發(fā)現(xiàn))還使用了權(quán)重屬性,LinearLayout默認的為true,下面結(jié)合一個小例子大家就會很快理解直接上代碼
我先設(shè)置為false,大家忽略其中的中文
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:baselineAligned="false"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始進行龜兔賽跑比賽了嗎"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
</LinearLayout>

Mou icon
設(shè)置為true后
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:baselineAligned="true"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始進行龜兔賽跑比賽了嗎"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="開始"
/>
</LinearLayout>

Mou icon
沒看到變化?

Mou icon
相信看了這張大家就明白了
設(shè)置為true時同時設(shè)置了layout_weight屬性控件的對齊方式會根據(jù)控件內(nèi)部的內(nèi)容對齊,當設(shè)置為false時會根據(jù)控件的上方對齊