2012-10-23 14 views
5

對不起,如果我問這樣一個基本的問題。我已經嘗試谷歌整個上午,並閱讀在developer.android.com的文件,但我找不到解決方案。Android GUI - 如何強制按鈕到下一行?

總之,我想提出,看起來像這樣的接口:

enter image description here

這是我到目前爲止有:

enter image description here

現在,我試圖將2個按鈕帶到下一行,但我仍然沒有運氣。如果我將android:orientation =「horizo​​ntal」更改爲「vertical」,則所有內容均垂直對齊。我試圖在Button標籤內放入android:orientation =「vertical」這一行,但這似乎不起作用。

我還能試試嗎?有人會給我幾個指針嗎? (我在Android開發和所有這些XML的東西新)。


下面是我的XML代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
> 

<EditText android:id="@+id/txt_Input" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:hint="@string/txt_Input" 

     android:layout_weight="4"      
/> 
<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/btn_Send" 

     android:layout_weight="1" 

     android:onClick="sendMessage" 
/> 

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/btn_Send" 

     android:layout_weight="1" 

     android:onClick="sendMessage" 
/> 

</LinearLayout> 

回答

4

只需使用RelativeLayout的,和你的按鈕應該是這個樣子:

<Button 
    android:id="@+id/send" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/btn_Send" 
    android:onClick="sendMessage" 
    android:layout_below="@+id/txt_Input" 
    android:layout_alignParentLeft="true"/> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/btn_Send" 
    android:onClick="sendMessage" 
    android:layout_below="@+id/txt_Input" 
    android:layout_toRightOf="@+id/send"/> 
+0

謝謝您的詳細解答。這非常有幫助! – TATN

+0

小修正,這是對RightOf,而不是Righof –

6

你把所有的項目在LinearLayout中與它的方向設置爲水平,因此行了所有的UI組件的水平。你需要做的是使用RelativeLayout,並將按鈕設置爲EditText下的佈局。

+2

另外,設置方向垂直,並使用嵌套水平線性佈局,以封閉的EditText下面的按鈕。 – withoutclass

+2

@withoutclass:那會比僅僅相對佈局效率低 – Asahi

+0

應該沒有太大區別。 – CaseyB

相關問題