2014-06-08 156 views
0

我想重新定位我的android應用程序佈局,我有2個EditText和一個按鈕。XML Android定位佈局

我想把它們放在彼此的下面,它現在並排。 這裏是我的代碼:

<TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="20dp" 
      android:background="@drawable/borderlayout" > 

      <EditText 
      android:id="@+id/titleText1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:hint="Title" /> 

     <EditText 
      android:id="@+id/descriptionText1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@+id/titleText1" 
      android:layout_weight="1" 
      android:hint="Description" /> 

     <Button 
       android:id="@+id/inputbutton1" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/descriptionText1" 
       android:layout_weight="1" 
       android:background="@drawable/custom_button" /> 
</TableRow> 

,這是它的外觀,當我運行(廣東話後的圖像又因爲低銷售代表) http://prntscr.com/3qyjpv

回答

0

必須使用LinearLayoutorientation=vertical

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <EditText 
     android:id="@+id/titleText1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:hint="Title" /> 

    <EditText 
     android:id="@+id/descriptionText1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/titleText1" 
     android:layout_weight="1" 
     android:hint="Description" /> 

    <Button 
      android:id="@+id/inputbutton1" 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/descriptionText1" 
      android:layout_weight="1" 
      android:background="@drawable/custom_button" /> 

+0

它的工作!謝謝 – meskh

0

更改爲與android:orientation="vertical"一個LinearLayout

0

正如你不應該使用表格中的HTML格式,所以你不應該使用TableLayout格式化Android中的GUI。保留使用TableLayout格式化數據表。

如果需要,您可以使用LinearLayout,但我更喜歡用於「強制」小部件相對於彼此的位置。