How to define a Android Multiline EditText

Defining an Android Mulitline EditText Field is done via the inputType=”textMultiline”. Unfortunately the text looks strangely aligned. To solve that also use the gravity=”left|top” attribute.

 <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:ems="10"
        android:gravity="left|top"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

With the gravity flag it looks like the following.

Without it, it looks like the following.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Android and tagged . Bookmark the permalink.