2014-09-01 67 views
2

我得到這個:我在做什麼重量有問題?

Inverted weights

但是我有這樣的佈局代碼:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <EditText android:id="@+id/editText_search" 
     android:layout_width="fill_parent" 
     android:layout_weight="0.7" 
     android:layout_height="wrap_content" 
     android:text="" /> 

    <Button android:id="@+id/button_search" 
     android:layout_width="fill_parent" 
     android:layout_weight="0.3" 
     android:layout_height="wrap_content" 
     android:text="@string/search" 
     /> 
</LinearLayout> 

所以,你可以看到,我希望按鈕爲30%,而到的EditText 70%

兩個問題:

  • 我是什麼做錯了嗎?
  • 我應該使用重量嗎?因爲在平板電腦30%的可能是太多的按鈕(也許我應該爲按鈕使用絕對值)
+0

是這個完整的XML,你對的LinearLayout的父母任何空白,爲平板電腦保持一個不同的XML文件,根據屏幕大小 – 2014-09-01 00:37:46

+0

添加weightSum =「1.0」至你的LinearLayout和子級應該有layout_width =「0dp」來保證。 – 2014-09-01 00:39:55

+0

不是不完整的XML ...這裏顯示的線性佈局(水平)是另一個線性佈局(垂直)的子節點 – sports 2014-09-01 00:40:33

回答

2

當使用重量,無論是layout_heightlayout_width必須0dp,這取決於你想要哪個軸伸展
在你的榜樣,你應該設置android:layout_width="0dp"

+0

如果我想拉伸水平線,我必須設置layout_width 0dp? – sports 2014-09-01 00:41:31

+1

是的,如果拉伸是水平的,寬度應該是0dp,如果拉伸是垂直的,高度應該是0dp – Houcine 2014-09-01 00:43:21

相關問題