Android GUI - 如何强制按钮到下一行?

标签 android user-interface layout

抱歉,如果我问的是这样一个基本问题。我整个早上都在谷歌上搜索,并通读了 developer.android.com 上的文档,但我找不到解决方案。

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

enter image description here

这是我目前所拥有的:

enter image description here

现在,我试图将 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>

最佳答案

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

关于Android GUI - 如何强制按钮到下一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13038469/

相关文章:

php - PHP 脚本在浏览器和 Android 应用程序中的不同输出

android - SharedPreference 值未更新

java - 在 JavaFX 8 中重新对齐 AnchorPane 中的组件

html - 如何在盒子内的 div 之间换行?

android - Gradle Android Buildscript Configuration with Flavors

以编程方式连接Android WiFi

javascript - Chrome 移动设备上 FB.ui 提要对话框中的空白页面

iphone - 如何让iPhone中的两个导航栏重叠?

html - 使用 CSS 创建响应式网格 (100% x 100%)

html - 对齐 &lt;input&gt; 和 <button> 标签