问大家一个小问题在如下例子中。。要用到layout_weight 这个属性值。则他的LinearLayout  的layout_width 必须设置成 fill_parent   设置成 wrap_content可以吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    >  
<TextView    
    android:id="@+id/a1"  
    android:layout_width="fill_parent"   
    android:layout_height="wrap_content"   
    android:text=""  
    android:layout_weight="1"  
    />  
<TextView    
    android:id="@+id/a2"  
    android:layout_width="fill_parent"   
    android:layout_height="wrap_content"   
    android:text=""  
    android:layout_weight="2"  
    />  
</LinearLayout>  

解决方案 »

  1.   

    好像必须要是fill_parent才行。
      

  2.   

    LinearLayout的layout_wdith或者layout_height(根据orientation)属性必须设置为fill_parent,其子view的layout_width或者layout_height(同样依据LinearLayout的orientation)应该设置为0dp。
    官方文档中描述如下:
    Tip: To create a proportionate size layout on the screen, create a container view group object with the layout_width and layout_height attributes set to fill_parent; assign the children height or width to 0 (zero); then assign relative weight values to each child, depending on what proportion of the screen each should have.