2011-05-05 77 views
0

我想要對齊這些輸入以在右側有一個自動完成框,在右側有一個較小的按鈕。不過,我最終得到了一個涵蓋所有內容的大型自動完成(第二個)。對齊按鈕問題

<RelativeLayout 
     android:layout_alignParentBottom="true" 
     android:id="@+id/transport_search" 
     android:background="@color/dark_grey" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 

     <AutoCompleteTextView 
      android:id="@+id/transport_autoCompleteFrom" 
      android:layout_width="fill_parent" 
      android:layout_weight="5" 
      ></AutoCompleteTextView> 

     <Button 
      android:id="@+id/transport_switchDirection" 
      android:layout_toRightOf="@+id/transport_autoCompleteFrom" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      ></Button> 

     <AutoCompleteTextView 
      android:id="@+id/transport_autoCompleteTo" 
      android:layout_width="fill_parent" 
      android:layout_weight="5" 
      ></AutoCompleteTextView> 

     <Button 
      android:id="@+id/transport_go" 
      android:layout_toRightOf="@+id/transport_autoCompleteTo" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      ></Button> 

    </RelativeLayout> 

我在做什麼錯?

+0

從你的描述,我不明白它是什麼,你正在試圖做的。一張圖片勝過千言萬語。 – 2011-05-05 03:06:37

回答

0

您可以在RelativeLayout中使用LinearLayout。下面顯示了兩行按鈕:

<LinearLayout android:id="@+id/buttons" android:layout_below="@id/aboveControl1" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:orientation="horizontal" android:weightSum="2" 
    android:layout_alignLeft="@id/otherControl1" android:layout_alignRight="@id/otherControl2" > 
    <Button android:id="@+id/button10" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Ok" android:layout_weight="1" /> 
    <Button android:id="@+id/button11" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Cancel" android:layout_weight="1" /> 
</LinearLayout> 
0

如果你喜歡使用RelativeLayout,或許下面的內容讓你更接近你想要達到的目標。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_alignParentBottom="true" 
    android:id="@+id/transport_search" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"> 
    <AutoCompleteTextView 
     android:id="@+id/transport_autoCompleteFrom" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:text="auto 1" /> 
    <Button 
     android:id="@+id/transport_switchDirection" 
     android:layout_toRightOf="@id/transport_autoCompleteFrom" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="button1" /> 
    <AutoCompleteTextView 
     android:id="@+id/transport_autoCompleteTo" 
     android:layout_below="@id/transport_autoCompleteFrom" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:text="auto 2" /> 
    <Button 
     android:id="@+id/transport_go" 
     android:layout_toRightOf="@id/transport_autoCompleteTo" 
     android:layout_below="@id/transport_switchDirection" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="button2" /> 
</RelativeLayout>

以下是此佈局的屏幕截圖。

此外,你可能想看看TableLayout是如何使用類似的結果在Android Create aligned fields Layout