关于Android布局weight权重设计

                                weight

以前一直是按默认的来设计的,或者自己定义16dp边距类似。现在要学习权重weight的概念。今天我们的目标是做到下面这个效果,主要是为了学习weight


=================================================================================

布局:


两个子组件依托于主linearlayout存在。

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp">

        <Button
            android:id="@+id/crime_data"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <CheckBox
            android:id="@+id/crime_solved"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/crime_solved_label" />

    </LinearLayout>

 此时看到button和checkbox都是weight都是以1:1来分配LinearLayout空间的。如果将button  weight改为2,那么将会分配2/3的空间,则checkbox得到剩余的1/3.

为了避开第一次的空间分配直接将width改为0dp即可。
 


 

猜你喜欢

转载自429899791.iteye.com/blog/2334518
今日推荐