其他分享
首页 > 其他分享> > Android多行edittext不会随着用户类型的增加而增加其高度

Android多行edittext不会随着用户类型的增加而增加其高度

作者:互联网

因此布局非常简单. 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,android-edittext,height,relativelayout,multiline
来源: https://codeday.me/bug/20190825/1722335.html