android - 如何在 Android Studio 上对齐屏幕底部的按钮
问题描述
我正在尝试制作一个表单来发送消息,我需要标题和收件人的电子邮件位于上半部分,中间占据了这个EditText et_mensaje
的大部分屏幕,而在屏幕的下半部分是发送按钮,但是在我的 xml 文件中,按钮超出框架。我不想将值放在et_mensaje
我希望它自动调整到不同屏幕的高度
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
>
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/NEGRO"
android:text="Message Demo"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_below="@id/text1"
android:orientation="horizontal">
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/LinearLayout1"
android:textColor="@color/NEGRO"
android:layout_weight="1"
android:textSize="16sp"
android:text="Para: " />
<EditText
android:id="@+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:inputType="textEmailAddress"
android:textSize="16sp"
/>
</LinearLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/NEGRO"
android:layout_below="@id/LinearLayout1"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:text="Mensaje:" />
<EditText
android:id="@+id/et_mensaje"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/NEGRO"
android:layout_below="@id/textView3"
android:layout_weight="1"
android:textSize="16sp"
android:background="@drawable/edittext_bg"
android:inputType="textPersonName"
/>
<Button
android:id="@+id/bt_SendButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/et_mensaje"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:text="ENVIAR MAIL" />
解决方案
如果您需要的所有内容都无法在屏幕上显示,那么您可以使用ScrollView以便滚动到屏幕底部。由于您的父布局是LinearLayout,因此您可以像现在一样在最后使用Send按钮。
如果您希望所有内容都显示在屏幕上(不使用ScrollView),那么您可以为每个组件设置权重。
(另外,我认为您不需要最外层(父级)LinearLayout;看起来您正在使用RelativeLayout。)
推荐阅读
- javascript - 如何在具有不同变量的javascript中重用函数
- javascript - 如何使用 React Hooks 指示请求正在加载,然后在请求完成后更改 UI?
- python - 在 python 中确定 mapreduce 作业中的数据重用
- kotlin - Kotlin 脚本找不到 Ktor CIO 类
- google-assistant-sdk - SynonymType.entities 的映射是什么样的?
- c# - 更新现有孩子而不是添加新孩子
- java - 如何在 Java Swing 中为按钮提供自定义形状?
- nginx - 当我添加第二个 nginx 服务器时,为什么我的 websocket 没有切换协议?
- html - 使 div 继续到新行而不是跳到新行
- python - 如何让 Kivy 应用程序在线程内运行?