2011-03-04 35 views
1

我正在使用Android的relativelayout,試圖使兩個按鈕並排排列。 但是,當我使用layout_toLeftOf時,我的button02突然消失。 這很好,如果我使用layout_toRightof。有人知道爲什麼使用relativelayout的「toLeftof」時,視圖消失

<Button 
    android:id="@+id/Button01" 
    android:layout_alignParentLeft="true" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@+id/Button01"> 
</Button> 

<Button 
    android:id="@+id/Button02" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@+id/Button02" 
    android:layout_toLeftOf="@+id/Button01" 
    android:layout_alignTop="@+id/Button01" 
    android:layout_alignBottom="@+id/Button01" 
    > 
</Button> 

回答

2

這是因爲第一個是左對齊;如果您將第二個按鈕放在第一個按鈕的左邊,它將會在屏幕之外。

所以,如果你在第一個按鈕來更改

android:layout_alignParentLeft="true" 

android:layout_alignParentRight="true" 

+0

啊哈!我真笨!! – Nohappy 2011-03-06 12:53:04

0

如果你想讓Button2留在Button1中,爲什麼要放置alignTop和alignBottom屬性?請刪除並看看。如果要將Button1放置在右側,還要刪除Button1的alignParentLeft。