LinearLayout中的baselineAligned屬性

相信在用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ì)齊

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,837評(píng)論 18 139
  • Android功能強(qiáng)大,界面華麗,但是眾多的布局屬性就害苦了開發(fā)者,下面這篇文章結(jié)合了網(wǎng)上不少資料.第一類:屬性值...
    HangChen閱讀 4,907評(píng)論 0 24
  • ¥開啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個(gè)線程,因...
    小菜c閱讀 6,497評(píng)論 0 17
  • 1、窗體 1、常用屬性 (1)Name屬性:用來獲取或設(shè)置窗體的名稱,在應(yīng)用程序中可通過Name屬性來引用窗體。 ...
    Moment__格調(diào)閱讀 4,586評(píng)論 0 11
  • 1、 聽說我的前公司倒閉了。 我一點(diǎn)兒也不吃驚,甚至覺得,這一天來的有點(diǎn)晚。 這并不是幸災(zāi)樂禍落井下石,畢竟早已經(jīng)...
    白大俠閱讀 5,917評(píng)論 72 90