2012-05-25 51 views
0

任何人都可以告訴layout_weigh sum在android中的工作方式。我已經爲線性佈局設置了weightsum 100,爲texview設置了layout_weight =「33」,而按鈕爲layout_weight =「67」。但是textview會變大大小layout_weighsum如何在android中工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    android:weightSum="100"> 
    <TextView android:text="left" android:textColor="#000000" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_weight="33" /> 
    <Button android:text="right" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_weight="67" /> 
</LinearLayout> 

感謝

+0

什麼是您的佈局的方向? – Akram

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="left" 
     android:textColor="#000000" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="right" /> 

</LinearLayout> 

請刪除機器人:weightSum = 「100」 和與此代碼嘗試。

0

android:layout_weight的工作不過是它用來爲其父佈局設置dp。

It can be Sum of 1 or 10 or 100. 

1) 0.8 and 0.2 

2) 80 and 20 

3) 800 and 200 

這三個選項是相同

您可以將上述重量增加子佈局。你可以參考Here