7

对不起,如果我问这样一个基本的问题。我整个早上都在尝试谷歌,并阅读了 developer.android.com 上的文档,但我找不到解决方案。

简而言之,我想做一个如下所示的界面:

在此处输入图像描述

这是我到目前为止所拥有的:

在此处输入图像描述

现在,我试图将 2 个按钮带到下一行,但我仍然没有运气。如果我将 android:orientation="horizo​​ntal" 更改为 "vertical",则所有内容都垂直对齐。我试图将 android:orientation="vertical" 线带入 Button 标记内,但这似乎不起作用。

我还能尝试什么?有人能给我一些指点吗?(我是 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

2 回答 2

6

您将 LinearLayout 中的所有项目的方向设置为 Horizo​​ntal,因此它水平排列所有 UI 组件。你需要做的是使用RelativeLayout并将按钮设置为EditText下方的布局。

于 2012-10-23T20:15:37.810 回答
6

只需使用 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"/>
于 2012-10-23T20:32:21.667 回答