我有4個水平線性佈局的按鈕。我想第四個按鈕的右邊緣與線性佈局的右邊緣對齊(等於屏幕寬度)我嘗試過使用android:layout_gravity =「right」,但它不起作用 - 右鍵是在第三個的右邊,但沒有對齊。我錯過了明顯的東西嗎?在main.xml中的android:layout_gravity效果?
main.xml中,只有相關的佈局僅params爲:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="fill_parent"
android:layout_width="wrap_content">
<Button SAME LAYOUT AS BUTTON 1>
<Button SAME LAYOUT AS BUTTON 1>
<Button
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
這似乎並不匹配在SDK參考layout_gravity所陳述的行爲:「定義如何放置視圖,它的兩個x軸和y軸,在其父視圖組內。「
Upvoted for great justice! – benvd 2010-09-29 15:06:25
謝謝Nik。我認爲用RelativeLayout進行控制似乎有更多的空間。這個按鈕仍然有點跳躍,但我會堅持下去! – NickT 2010-09-29 18:52:36
@NickT,保持它,並確保在每個控件上定義layout_align *以使它們正確對齊。有關RelativeLayout技巧的更多信息,請參閱:http://www.nikreiman.com/2010/09/android-relativelayout-ninja-fu-or-how.html – 2010-09-29 19:55:51