Luke
Luke

Reputation: 1079

Android increase height of parent when textMultiLine wraps to new line

I have a fragment that shows a chat session and then below it an EditText and a Button

Right now I have the height of the RelativeLayout containing the EditText and Button hard coded.

How do i have the RelativeLayout height only be the height of a single line EditText and when the user types enough text to warrant a new line of text dynamically re-size the height to be just big enough to contain the now larger EditText?

For anyone that has used the Google Voice app or the stock messaging app you can see this in action when replying to a message.

I've include my current layout below.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/bottom_bar"
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:layout_alignParentBottom="true"
        android:minHeight="60dp" >

        <ImageButton
            android:id="@+id/sendButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="false"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="false"
            android:layout_centerVertical="true"
            android:background="@null"
            android:onClick="sendMessage"
            android:paddingBottom="15dp"
            android:paddingRight="5dp"
            android:paddingTop="10dp"
            android:src="@drawable/send" />

        <EditText
            android:id="@+id/sendText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="false"
            android:layout_centerVertical="true"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_toLeftOf="@id/sendButton"
            android:hint="Enter Message"
            android:inputType="textMultiLine" >

        </EditText>

    </RelativeLayout>

    <fragment
        android:id="@+id/chatfragment"
        android:name="android.support.v4.app.ListFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottom_bar"
        android:layout_alignParentTop="true" />

</RelativeLayout>

Upvotes: 1

Views: 1766

Answers (1)

Sam
Sam

Reputation: 86948

Have you tried setting the height of your nested RelativeLayout to wrap_content?

<RelativeLayout
    android:id="@+id/bottom_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:minHeight="60dp" >

Upvotes: 3

Related Questions