首页 > 解决方案 > 如何在 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" />

标签: android

解决方案


如果您需要的所有内容都无法在屏幕上显示,那么您可以使用ScrollView以便滚动到屏幕底部。由于您的父布局是LinearLayout,因此您可以像现在一样在最后使用Send按钮。

如果您希望所有内容都显示在屏幕上(不使用ScrollView),那么您可以为每个组件设置权重。

(另外,我认为您不需要最外层(父级)LinearLayout;看起来您正在使用RelativeLayout。)


推荐阅读