gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:12:28 24 4
gpt4 key购买 nike

这看起来很简单,但我无法让它工作。我想在屏幕底部放置一个按钮,让 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com