2011-03-04 39 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。