LinearLayout中的baselineAligned属性

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

Set android:baselineAligned="false" on this element for better performance less

在使用lint检查时也会出现

Missing baselineAligned attribute

先来看baselineAligned这个属性的字面意思baseline Aligned基线对齐
那和我们平时的开发有什么关系呢
出现此警告时大多(其他还没发现)还使用了权重属性,LinearLayout默认的为true,下面结合一个小例子大家就会很快理解直接上代码

我先设置为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

设置为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

相信看了这张大家就明白了
设置为true时同时设置了layout_weight属性控件的对齐方式会根据控件内部的内容对齐,当设置为false时会根据控件的上方对齐

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,860评论 18 139
  • Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料.第一类:属性值...
    HangChen阅读 4,907评论 0 24
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,508评论 0 17
  • 1、窗体 1、常用属性 (1)Name属性:用来获取或设置窗体的名称,在应用程序中可通过Name属性来引用窗体。 ...
    Moment__格调阅读 4,588评论 0 11
  • 1、 听说我的前公司倒闭了。 我一点儿也不吃惊,甚至觉得,这一天来的有点晚。 这并不是幸灾乐祸落井下石,毕竟早已经...
    白大侠阅读 5,926评论 72 90