android - 如何在android studio中将居中按钮放在2个线性布局下方
问题描述
我的目标是有 2 列带有一个编辑文本和几个按钮,但我需要屏幕底部的一个按钮来确认这些值。我无法将其置于屏幕底部并使其居中。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="@+id/etWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:hint="@string/We"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="@+id/etThey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:hint="@string/They"/>
</LinearLayout>
解决方案
此XML布局将帮助您
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="@+id/etWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:hint="@string/We"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="@+id/etThey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:hint="@string/They"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
在我看来使用RelativeLayout
android:layout_alignParentBottom="true"
推荐阅读
- flask - 即使遵循不和谐 oauth2 的工作示例,authlib 也会引发 invalid_client 异常
- c# - 我是 MVC 和 C# 的新手并且收到此错误传递到字典中的模型项的类型为 'System.Linq.Enumerable+WhereSelectListIterator
- ios - 无法从构建环境成功上传 DSYM 获取 Google 服务文件中的 GOOGLE_APP_ID
- flutter - 将编码图像列表转换为 PDF
- java - 如何使用 TestRestTemplate 集成测试 RESTful APIs PUT 端点?
- c - 写入文件切断第二行 - C
- apache-spark - NameError:名称“countryCodeMap”未定义
- html - 如何在 Html 代码中正确格式化 JSON
- php - 如何在多个域别名上运行 Magento 2.3,但只使用一个网站(和一个商店视图)
- javascript - 如何在 Node.JS 中更新纯 .js 文件?