2015-10-05 52 views
0

當我指定的發言權和image view之間的weight且所包含相同linear layout我應該可以在layout_width值設置爲內linear layout指定layout_width?它似乎不應該被設置,因爲我說我想要其他layout佔用90%的空間,而image view佔用10%的空間。Android的 - 使用layout_weight時

而且好像我可以設置image view有10%的空間和layout有90%的空間,但我仍然可以指定image viewdp's值?

在這種情況下,我應該只設置在dp's值的image,然後指定的1爲其他layout一個weight

感謝

+0

請發表你試過到目前爲止。 – Tauqir

+0

好吧,我已經嘗試了幾個不同的東西,它們在模擬器中看起來很好,所以我在問什麼是使用權重時指定layout_width的正確權重,以及如果可以使用layout_weight,然後將layout_width值設置爲DP的? – berimbolo

+1

將寬度設置爲0dp。 – StG

回答

1

在這種情況下,你layout_width應該是0dp。如果將重量參數定義爲0dp以外的其他寬度,您還將得到一個皮棉警告。

refer this瞭解更多詳情。

+0

好的,謝謝Rahul,你能不能更新一下,當指定圖像的寬度爲150dp時,是否應該使用佈局權重,如果其他視圖包含指定其重量爲1,填補其餘的空間或應該是match_parent? – berimbolo

+0

[請參閱本文](http://developer.android.com/guide/topics/ui/layout/linear.html)瞭解詳情。閱讀完之後你會知道重量是如何工作的。 –

1

在佈局中使用重量時。 你會想要做到這一點。

父佈局將使用值爲10的weightSum=10,但它可以是我們想要的任何值。 爲兒童佈局。都應該是layout_width="fill_parent"然後你就可以設置layout_weight="2"爲孩子之一,然後layout_weight="8"爲其他孩子

像這樣

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


<imageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="8" 
    /> 

<LinearLayoout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" />