Android 安卓:如何使用下面的按钮来布局全屏编辑文本?

Android 安卓:如何使用下面的按钮来布局全屏编辑文本?,android,Android,这似乎很简单,但我无法让它工作。我想在屏幕底部放置一个按钮,让EditText占据剩余的可用空间。下面的布局显示创建一个占据全屏但按钮不可见的EditText <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

这似乎很简单,但我无法让它工作。我想在屏幕底部放置一个按钮,让EditText占据剩余的可用空间。下面的布局显示创建一个占据全屏但按钮不可见的EditText

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/textField"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </EditText>
    <Button
        android:id="@+id/button"
        android:text="text"
        android:layout_below="@id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>

</RelativeLayout>


因为布局的原因,您需要使用正确的布局。例如,在这种情况下,线性布局可能会有更大的帮助。

在您的RelativeLayout中尝试以下方法:

<EditText
    android:id="@+id/textField"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/button" />

<Button
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

原始布局的问题是EditText的高度设置为
match\u parent
,而按钮设置为低于此高度
match_parent
导致编辑文本占据屏幕的整个高度,按下屏幕底部下方的按钮

通过告诉按钮将其自身与屏幕底部对齐,然后告诉编辑文本将其自身置于屏幕底部上方,您应该能够实现所需的功能