android UI设计 layout_weight解析

来源:互联网 发布:淘宝一元拍入口 编辑:程序博客网 时间:2024/05/16 15:18
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <TextView android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="Detail"        style="?android:listSeparatorTextViewStyle"/>    <LinearLayout         android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="16dp"        android:layout_marginRight="16dp"        >        <Button             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="Wed Oct 17 15:49:50 EDT 2012"/>        <CheckBox             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="solved"/>    </LinearLayout></LinearLayout>

效果图:
这里写图片描述

如果把android:layout_weight=”1”改为android:layout_weight=”0”

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <TextView android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="Detail"        style="?android:listSeparatorTextViewStyle"/>    <LinearLayout         android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="16dp"        android:layout_marginRight="16dp"        >        <Button             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0"            android:text="Wed Oct 17 15:49:50 EDT 2012"/>        <CheckBox             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0"            android:text="solved"/>    </LinearLayout></LinearLayout>

效果图:
这里写图片描述

让LinearLayout只考虑android:layout_weight来分配空间,令android:layout_weight=”0”,这时候控件等分。

而android:layout_weight=”1”,会结合android:layout_width和android:layout_weight来划分控件,所以第一张图Button内容多,区域也就占得多。

0 0
原创粉丝点击