Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an EditText's initial height while allowing it to expand when overflows

I am currently working on an android app and i'm having some problems with EditText.

I want to create an editText with an empty string starting off with the height equivalent to 1 or more lines and maintaining that height, but allowing it to grow when text starts to overflow beneath the current size.

I tried several things :

  1. If I set the Edittext's size to a certain value, it doesn't grow... the previous lines just go up and become invisible

  2. When I don't set the size and use the default height, then the edittext always starts off with the height of two lines, not 1 line.

How can I fix this?

like image 943
NamHo Lee Avatar asked Sep 07 '25 09:09

NamHo Lee


2 Answers

How about using these option?

android:maxHeight="100dip"
android:minHeight="40dip"

MaxHeight will force your EditText's height no more than 100dip.

MinHeight will force your EditText's height minimum is 40dip.

Example)

<EditText
    android:id="@+id/somethingEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="56dip"
    android:maxHeight="200dip"
    android:minLines="1" />

This code will force your EditTex's height range to '56dip ~ 200dip'

like image 98
WindSekirun Avatar answered Sep 09 '25 01:09

WindSekirun


You can set minimum lines using minLines Property of edittext, also use height as wrap content to make it expandable.

<EditText 
android:width = "match_parent"
android:height= "wrap_content"
android:minLines="1"/>
like image 33
Pro Mode Avatar answered Sep 09 '25 00:09

Pro Mode