Layout_weight

首先按照控件的的尺寸进行分配,然后剩下的空间在按照weight的比例进行分配

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="111111111111111" 
        android:layout_weight="1"
        android:background="#ff3311"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2" 
        android:layout_weight="2"
        android:background="#2255dd"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3" 
        android:layout_weight="3"
        android:background="#ff6611"/>

</LinearLayout>

首先会按照控件本身分配,分配好tv1,然后按权重分配tv2和他tv3

如果要想让一个控件占一行的一半怎么办?这时候我们要在layout里加一个weightSum=2

然后让那个控件的weight=1,就可以了

posted @ 2015-10-21 20:05  aaddrrooiidd  阅读(84)  评论(0编辑  收藏  举报