相信在用studio寫布局xml的時(shí)候LinearLayout會(huì)報(bào)一些警告
Set android:baselineAligned="false" on this element for better performance less
在使用lint檢查時(shí)也會(huì)出現(xiàn)
Missing baselineAligned attribute
先來看baselineAligned這個(gè)屬性的字面意思baseline Aligned基線對(duì)齊
那和我們平時(shí)的開發(fā)有什么關(guān)系呢
出現(xiàn)此警告時(shí)大多(其他還沒發(fā)現(xiàn))還使用了權(quán)重屬性,LinearLayout默認(rèn)的為true,下面結(jié)合一個(gè)小例子大家就會(huì)很快理解直接上代碼
我先設(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="開始進(jìn)行龜兔賽跑比賽了嗎"
/>
<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="開始進(jìn)行龜兔賽跑比賽了嗎"
/>
<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í)同時(shí)設(shè)置了layout_weight屬性控件的對(duì)齊方式會(huì)根據(jù)控件內(nèi)部的內(nèi)容對(duì)齊,當(dāng)設(shè)置為false時(shí)會(huì)根據(jù)控件的上方對(duì)齊