Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - EditText multiline forced to fill height

I need a EditText that fills in height my window. I'm using this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

<EditText
    android:id="@+id/text_editor"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:gravity="top|left"
    android:inputType="textMultiLine"
    android:textColor="@android:color/white" />

</ScrollView>

But all I get is a one line EditText that will be longer and scrollable once I write something on multiline typing the return button. I know I can set the line number, but in this case it should work on different devices and every device (I guess) has different amount of lines.

How can I force it to fill the device in height?

Any tips?

like image 628
Lorenzo Sciuto Avatar asked Jun 20 '12 13:06

Lorenzo Sciuto


2 Answers

Try to use (without ScrollView):

<EditText
    android:id="@+id/text_editor"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:gravity="top|left"
    android:textColor="@android:color/white" />
like image 116
Alex Kucherenko Avatar answered Nov 08 '22 08:11

Alex Kucherenko


Try setting this for EditText, I had the same thing, this will work.

<EditText
android:id="@+id/text_editor"
android:layout_width="match_parent"
**android:layout_height="wrap_content"**
android:background="#ff0000"
android:gravity="top|left"
android:inputType="textMultiLine"
android:textColor="@android:color/white" />

and you can also use this one to set exactly how many lines you need,

android:lines="number of Lines"
like image 3
osayilgan Avatar answered Nov 08 '22 09:11

osayilgan