美文网首页
LinearLayout中的baselineAligned属性

LinearLayout中的baselineAligned属性

作者: 随心随性_0a25 | 来源:发表于2020-04-10 10:43 被阅读0次

相信在用studio写布局xml的时候LinearLayout会报一些警告

Set android:baselineAligned="false"onthiselementforbetter performance less

在使用lint检查时也会出现

Missing baselineAligned attribute

先来看baselineAligned这个属性的字面意思baseline  Aligned基线对齐

那和我们平时的开发有什么关系呢

出现此警告时大多(其他还没发现)还使用了权重属性,LinearLayout默认的为true,下面结合一个小例子大家就会很快理解直接上代码

我先设置为false,大家忽略其中的中文

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:baselineAligned="false"android:layout_height="match_parent"><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始进行龟兔赛跑比赛了吗"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/></LinearLayout>

Mou icon

设置为true后

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:baselineAligned="true"android:layout_height="match_parent"><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始进行龟兔赛跑比赛了吗"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="开始"/></LinearLayout>

Mou icon

没看到变化?

Mou icon

相信看了这张大家就明白了

设置为true时同时设置了layout_weight属性控件的对齐方式会根据控件内部的内容对齐,当设置为false时会根据控件的上方对齐

作者:橘座大人

链接:https://www.jianshu.com/p/07ba80fdd86a

相关文章

网友评论

      本文标题:LinearLayout中的baselineAligned属性

      本文链接:https://www.haomeiwen.com/subject/dgblmhtx.html