簡體   English   中英

Android GUI - 如何強制按鈕到下一行?

[英]Android GUI - How to force a button to the next line?

對不起,如果我問這樣一個基本問題。 我整個上午都試圖谷歌,並閱讀developer.android.com上的文檔,但我找不到解決方案。

簡而言之,我想創建一個如下所示的界面:

在此輸入圖像描述

這是我到目前為止:

在此輸入圖像描述

現在,我正在嘗試將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>

您擁有LinearLayout中的所有項目,其方向設置為“水平”,因此它會水平排列所有UI組件。 您需要做什么使用RelativeLayout並將按鈕設置為EditText下面的布局。

只需使用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"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM