android線性佈局佈局的layout_weight

對於LinearLayout的layout_weight屬性,很多人都很瞭解,今天我把我的一本android書又從第一頁開始翻,特意自己寫了demo來測試這個屬性,發現了一個很有趣的現象.
android_width會影響到android_weight

看下面了兩個佈局文件,他們的差別只是layout_width的值.一個fill_parent,另一個是wrap_content

<?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_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="111"
    android:background="#ff0000"
    />
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="2"
    android:text="22"
    android:background="#00ff00"
    />
   <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="3"
    android:background="#0000ff"
    android:text="33"
    />
</LinearLayout>
 

 

<?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_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="111"
    android:background="#ff0000"
    />
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="2"
    android:text="22"
    android:background="#00ff00"
    />
   <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="3"
    android:background="#0000ff"
    android:text="33"
    />
</LinearLayout>
 

 
 上面的佈局代碼分別對應下面的兩張圖片,出來的效果是完全不一樣的,所以當在使用layout_weight的時候,layout_width的值也是需要關心的.