您的位置:首页 > 移动开发 > Android开发

android LinearLayout android:baselineAligned属性

2015-10-29 16:16 567 查看
这个属性可能大家使用不多,但有时候会产生莫名其妙的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: