Android:如何布局全屏 EditText,下面有一个按钮?

标签 android

这看起来很简单,但我无法让它工作。我想在屏幕底部放置一个按钮,让 EditText 占据剩余的可用空间。下面的布局显示创建了一个占据全屏但 Button 不可见的 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_parent 而您的按钮设置为低于该高度。 match_parent 导致 EditText 占据屏幕的整个高度,插入屏幕底部下方的按钮。

通过让按钮与屏幕底部对齐,然后让 EditText 将自己置于其上方,您应该能够实现您正在寻找的内容。

关于Android:如何布局全屏 EditText,下面有一个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29239040/

相关文章:

Android:直接从 SQLite 数据库填充 ListView - 不使用 ArrayList

java - 将数据填充到 Listview 但 Arrayadapter 不工作

android - ExoPlayer 获取可用的音轨并在它们之间切换

android - 在 adt 20 中关闭 logcat 中的换行符

android - 找不到 com.android.tools.build :gradle:2. 3.3

android - unity3d everyplay游戏视频闪电很奇怪-黑白带闪电

android - 让 Android 上的 WebView 使用 prefers-color-scheme : dark

android - 如何使用 FB API 从 Android 应用程序在 Facebook 上发布链接?

java - Eclipse, ImageView 上的 View 布局

java.lang.RuntimeException : Unable to start activity ComponentInfo(android. view.InflateException:)