81

Here is my layout:

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

    <EditText
        android:id="@+id/etTweetReview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:ems="10"
        android:hint="Discuss up to 140 characters"
        android:imeOptions="actionDone"
        android:inputType="textCapSentences"
        android:lines="2"
        android:maxLength="140"
        android:paddingBottom="10dp"
        android:singleLine="false" />

    <Button
        android:id="@+id/theReviewBarButton"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="5dp"
        android:text="Submit Review"
        android:textSize="22sp" />

    <Spinner
        android:id="@+id/spinnerSort"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" />

    <ListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:scrollbars="none"
        android:layout_marginRight="5dp"
        android:layout_marginTop="8dp" >
    </ListView>

</LinearLayout>

When that EditText box gets to the end, I want it to wrap to the next line. Right now, it just keeps going right moving everything left off screen.

TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
  • 1
    Possible duplicate of [Android Word-Wrap EditText text](http://stackoverflow.com/questions/3276380/android-word-wrap-edittext-text) – blahdiblah Feb 12 '13 at 03:00

6 Answers6

159

Similar to another question:

Android Word-Wrap EditText text

Here's some example XML code:

<EditText
    android:id="@+id/edtInput"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:hint="@string/compose_hint"
    android:inputType="textCapSentences|textMultiLine"
    android:maxLength="2000"
    android:maxLines="4" />
Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
41

Assume that you just want to have one line at first then expand it to 5 lines and you want to have maximum 10 lines.

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/etMessageBox"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:autoLink="all"
    android:hint="@string/message_edit_text_hint"
    android:lines="5"
    android:minLines="1"
    android:gravity="top|left"
    android:maxLines="10"
    android:scrollbars="none"
    android:inputType="textMultiLine|textCapSentences"/>

By increasing android:lines you can define expand it how many lines.

Nicolas
  • 6,611
  • 3
  • 29
  • 73
Hesam
  • 52,260
  • 74
  • 224
  • 365
  • 3
    What if we want to start with 4 lines and have the text scroll upward when the user has entered more than 4 lines worth of text? – Ivan Apr 13 '17 at 16:50
12

Just add android:lines="6" to your edittext

 <Edittext
      android:id="@+id/edt_address"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:inputType="textMultiLine"
      android:maxLines="6"             
      android:lines="6"
      android:layout_marginTop="@dimen/activity_vertical_margin"
      android:gravity="left"/>
Yyy
  • 2,285
  • 16
  • 29
4

try this code

<EditText
    android:id="@+id/"edittext01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textCapSentences|textMultiLine"
    android:maxLength="100"
    android:maxLines="10"/>
KUSHA B K
  • 1,489
  • 13
  • 20
4

You need your EditText height set to android:layout_height="wrap_content"

&

android:lines="5"

This did the trick for me inside ConstraintLayout

Nishant Rajput
  • 2,053
  • 16
  • 28
1

Remove this line form your EditText

android:inputType="textCapSentences"

and add this line with number of lines required by you

android:lines="2"

Hope this helps you

Deepak
  • 29
  • 4