2012-09-19 30 views
0

下面的代碼:我的觀點怎麼沒有垂直設置?

<RelativeLayout 
      android:id="@+id/top_lay2" 
      android:layout_below="@id/top_lay1" 
      android:layout_width="fill_parent" 
      android:layout_marginTop="10dp" 
      android:orientation="vertical" 
      android:layout_height="wrap_content" 
      android:background="@drawable/customrect"> 
<TextView 
      android:layout_gravity="center" 
      android:layout_width="fill_parent" 
      android:layout_height="wrao_content" 
      android:textColor="@color/white1" 
      android:text="some text" 
     /> 
<Button 
      android:layout_gravity="center" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="click me" 
    /> 

    </RelativeLayout> 

從這個XML代碼,我只是意見將被垂直相對於其他顯示的,而是它們堆疊在彼此。這裏有什麼問題?

回答

1

在LinearLayout中,你的字段都要垂直顯示。但是在RelativeLayout中,你必須指定它們相對於彼此的位置。所以,如果你用「LinearLayout」替換「RelativeLayout」,你就全都設置好了。

0

A RelativeLayout RelativeLayout需要描述其子女相對於彼此的位置。

如果您希望定位自動發生,請使用LinearLayout,並將其方向設置爲垂直。