您的位置:首页 > 其它

LinearLayout内的权重属性 weight

2016-05-04 23:37 344 查看
1、首先设置是横向还是纵向,如果是横向,设置横向width 都是0dp ,weight就是对应的权重,比如,两个按钮 权重分别是1,2,那么第一个按钮占得距离是1/3,第二个是2/3

2、如果对应的宽度或者高度是match,那么计算权重时需要首先计算出总长度或者总高度, 公式= 原宽度+剩余宽度的百分比

例如: 两个横向的按钮 宽度都是 match_parent ,权重分别是1,2 那么第一个按钮的距离=L+(L-2L)*(1/3)= 2/3L

3、如果三个控件使用权重,
android:baselineAligned="false"


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">

<TextView
android:background="#ff0000"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:text="abdcde/ncdd"/>
<TextView
android:background="#0f0"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="2"
android:text="第二个"/>
<TextView
android:background="#00f"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="3"
android:text="第三个"/>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: