android LinearLayout android:baselineAligned属性

来源:互联网 发布:linux snmp 配置文件 编辑:程序博客网 时间:2024/06/04 18:43

这个属性可能大家使用不多,但有时候会产生莫名其妙的bug,当然这个bug是在布局方面,首先看一个简单的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >    <TextView        android:layout_width="0dp"        android:layout_height="48dp"        android:layout_weight="1"        android:text="11111111111"        android:background="#00ffff"        android:gravity="center"         />  <TextView        android:layout_width="0dp"        android:layout_height="48dp"        android:layout_weight="2"        android:text="22222222222222"        android:background="#ff00ff"        android:gravity="center"         />    <TextView        android:layout_width="0dp"        android:layout_height="48dp"        android:layout_weight="3"        android:text="3333333333333333333"        android:background="#ff0000"        android:gravity="center"         /></LinearLayout>

效果图:


这看起来很神奇,但是仔细发现他的第一行文字都是在同一条水平线上,这就是textview的父viewLinearlayout默认的属性android:baselineAligned为true,我们只要手动的去设置这个属性把这个属性改为false,不参考父view的中间线对齐就ok


0 0