2013-04-03 11 views
2

這裏是我的佈局:toRightOf無法正常運行在Android佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/outerBox" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" > 

<GridLayout 
    android:id="@+id/checksHere" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="5" 
    android:columnWidth="100dp" /> 

<GridLayout 
    android:id="@+id/textHere" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/checksHere" 
    android:columnCount="4" /> 

<Button 
    android:id="@+id/submitButton" 
    android:layout_width="185dip" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@id/outerBox" 
    android:layout_below="@id/textHere" 
    android:layout_margin="3dip" 
    android:onClick="submit" 
    android:text="@string/submit" /> 

<Button 
    android:id="@+id/cancelButton" 
    android:layout_width="185dip" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/textHere" 
    android:layout_margin="3dip" 
    android:layout_toRightOf="@id/submitButton" 
    android:onClick="next" 
    android:text="@string/cancel" /> 

<Button 
    android:id="@+id/backButton" 
    android:layout_width="185dip" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/textHere" 
    android:layout_margin="3dip" 
    android:layout_toRightOf="@id/cancelButton" 
    android:onClick="next" 
    android:text="test" /> 

</RelativeLayout> 

我有個親戚佈局。該佈局頂部有兩個網格佈局,可以在我的java代碼中使用文本或檢查來填充佈局。它們可以是空白的。然後我有三個按鈕。前兩個按鈕在屏幕上顯示很好。第三個按鈕就坐在第一個按鈕的頂部: enter image description here

我換了第三個按鈕(後退按鈕)是toRightOf提交按鈕只是爲了看看會發生什麼。如預期的那樣,它位於cancelButton的頂部。我覺得我錯過了一個簡單的基礎,但是我一直沒有弄明白。

+2

你可以嘗試從最後一個按鈕中刪除'android:layout_below =「@ id/textHere」'嗎? – WarrenFaith 2013-04-03 20:26:01

+0

它進入佈局的頂部,與之前的X位置相同。 – clavio 2013-04-03 20:30:48

+0

並且您已清理該項目以確保?有時構建過程會「忘記」xml解析... – WarrenFaith 2013-04-03 20:36:07

回答

4

嗯,這並不一定解決RelativeLayout的問題,但你總是可以將三個按鈕組合在一個LinearLayout中。這應該防止按鈕重疊。

0

我不確定,但在eclipse中進行測試時,將所有android:layout_width="185dip"更改爲android:layout_width="wrap_content"的按鈕適用於我。