抱歉,如果我问的是这样一个基本问题。我整个早上都在谷歌上搜索,并通读了 developer.android.com 上的文档,但我找不到解决方案。
简而言之,我想制作一个如下所示的界面:
这是我目前所拥有的:
现在,我试图将 2 个按钮放到下一行,但我仍然没有成功。如果我将 android:orientation="horizontal"更改为 "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/