user692168
user692168

Reputation:

Android multiline edittext not increasing its height as the user types

So the layout is quite simple. A ListView occupying most of the screen, and a RelativeLayout at the bottom containing the EditText and a Button to the right. Everything looks great, but the problem is that as the user types and enters new lines, the EditText is not increasing its height just enough so that the user can see all the text types without scrolling. You would think that using WRAP_CONTENT on both the EditText and its parent RelativeLayout would take care of that, but it doesn't for some reason. Any ideas? Here's the Layout 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>

Upvotes: 3

Views: 4163

Answers (2)

user692168
user692168

Reputation:

So in the end I couldn't figure it out. Instead, I used a LinearLayout instead of the RelativeLayout in the nested Layout. Here's the new Layout 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>

Upvotes: 7

Femi
Femi

Reputation: 64690

Try setting the maxlines property, perhaps.

Upvotes: 0

Related Questions