我需要設置我的視圖的寬度作爲在屏幕的寬度的50%,然後水平居中同時潛在地具有可出現連接到左或右側的1個或多個按鈕這一觀點屏幕。的Android百分比寬度佈局
我使用的相對佈局,這樣我可以放置一個線性佈局與重量來獲得,同時將在連接到RL的左或右邊緣LL的頂部上的任何按鈕居中我的50%。但是這種佈局缺少藍色的中間欄。如果我將中間視圖layout_weight設置爲1,則會得到3個相同大小的條。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp">
<LinearLayout
android:id="@+id/stupid_android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:layout_weight="1" />
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:layout_weight="2" />
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
這是怎麼了'layout_weight'作品。 'layout_weight'告訴你如何** **剩餘在父空間'View'應該由孩子'View'的devided。在你的情況首先'View'有'安卓layout_width'設置爲'fill_parent'所以沒有任何實際剩餘空間。我不知道爲什麼最後一個視圖仍然可見,因爲我只能看到第一個視圖。 – 2013-03-04 15:16:11