android:layout_weight字面理解为比重,刚开始我把它理解为每个内容的百分比,但实际应用中似乎不然,于是做了如下试验,以求证layout_weight的分配原则。

首先,新建一个工程,在编辑main.xml如下:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="horizontal" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_weight="1" android:text="1"
		android:gravity="center_horizontal" android:layout_width="wrap_content"
		android:layout_height="fill_parent" android:background="#00f"></TextView>
	<TextView android:layout_weight="1" android:text="1"
		android:gravity="center_horizontal" android:layout_width="wrap_content"
		android:layout_height="fill_parent" android:background="#f00"></TextView>
	<TextView android:layout_weight="1" android:text="1"
		android:gravity="center_horizontal" android:layout_width="wrap_content"
		android:layout_height="fill_parent" android:background="#0f0"></TextView>
	<TextView android:layout_weight="1" android:text="1"
		android:gravity="center_horizontal" android:layout_width="wrap_content"
		android:layout_height="fill_parent" android:background="#ff0"></TextView>
	<TextView android:layout_weight="1" android:text="1"
		android:gravity="center_horizontal" android:layout_width="wrap_content"
		android:layout_height="fill_parent" android:background="#f0f"></TextView>
</LinearLayout>



posted on 2010-10-15 14:33  四渡冰点  阅读(2069)  评论(2编辑  收藏  举报