gpt4 book ai didi

Android多行编辑文本不会随着用户键入而增加其高度

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:16 27 4
gpt4 key购买 nike

因此布局非常简单。一个 ListView 占据了大部分屏幕,底部的一个 RelativeLayout 包含 EditText 和一个 Button正确的。一切看起来都很好,但问题是当用户键入并输入新行时,EditText 没有增加其高度,以至于用户无需滚动即可看到所有文本类型。您可能认为在 EditText 及其父级 RelativeLayout 上使用 WRAP_CONTENT 会解决这个问题,但由于某些原因并没有。有任何想法吗?这是布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:id="@+id/postCommentRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:visibility="visible" >

<Button
android:id="@+id/viewCommentsPostCommentButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:text="@string/post" />

<EditText
android:id="@+id/viewCommentsInsertCommentTextEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/viewCommentsPostCommentButton"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_toLeftOf="@+id/viewCommentsPostCommentButton"
android:ems="10"
android:hint="@string/enter_comment"
android:inputType="textCapSentences|textMultiLine" >

<requestFocus />
</EditText>

</RelativeLayout>

<ListView
android:id="@+id/entriesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/postCommentRelativeLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false" >

</ListView>
</RelativeLayout>

最佳答案

所以最后想不通。相反,我在嵌套布局中使用了 LinearLayout 而不是 RelativeLayout。这是新的布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:id="@+id/postCommentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:visibility="visible" >

<EditText
android:id="@+id/viewCommentsInsertCommentTextEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/enter_comment"
android:inputType="textCapSentences|textMultiLine" />

<Button
android:id="@+id/viewCommentsPostCommentButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="4"
android:text="@string/post" />

</LinearLayout>

<ListView
android:id="@+id/entriesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/postCommentLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false" >

</ListView>
</RelativeLayout>

关于Android多行编辑文本不会随着用户键入而增加其高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16182526/

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