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

最近修改lint警告时发现一个针对LinerLayout的异常提示:“Set android:baselineAligned="false" on this element for better performance”

网上查了一下android:baselineAligned=”false”,发现它是LinerLayout用来对齐文案的属性,默认值是true。具体可参见这篇文章:http://blog.csdn.net/chenbengang/article/details/48154057?ticket=ST-34523-bJ5ojNUHGwYXx7O3jds2-passport.csdn.net

那么既然默认值是true,为什么lint要告诉我们把它置为false呢?

请看lint报错的问题布局:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#99ffffff"
                android:textSize="14dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:textColor="@color/white"
                android:textSize="30dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#99ffffff"
                android:textSize="14dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:textSize="30dp" />
        </LinearLayout>
    </LinearLayout>

布局的最外层LinearLayout嵌套了两个子的LinearLayout,每个子LinearLayout又嵌套了两个TextView;
Set android:baselineAligned="false" on this element for better performance这个提示就是针对最外层的LinerLayout的;

原因是:当LinerLayout的子View都是ViewGroup(自定义控件除外)时,Lint认为它的子View已经不需要基准线对齐了,为了不让LinerLayout去做无用的计算对齐的操作,提出了如上警告,修改掉之后就可以提高性能。

实编程中,我们应该时刻注意,如果是不需要用到android:baselineAligned的地方,都可以设置成false,这样也可以提高性能!(个人觉得基准线对齐在英文里面用的比较多,中文里面基本用不到……)

本文仅代表作者的个人见解,如有不足,请各位斧正,谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值