androidandroid-edittextheightandroid-wrap-content

Limited WRAP_CONTENT for edittext


I want that when my edittext is empty it's height is 40px, i.e., it takes space of only one line. And when text is typed the height increases. It should function more like the WRAP_CONTENT on its height, but I want that once it reaches the height of (5*40px) or 200px, i.e., space of 5 lines. It doesn't increases anymore. It acts as if it's height is fixed 200px. How can I access this type of height feature.

Please try to help by providing Programmatic reference rather than XML reference. Thanks in advance...


Solution

  • You should check this question out. It has exactly what you need. Next time while asking a question, please do a little bit research.

    Set limitation for EditText height and Maximum lines

    Also, there's a tag called android:maxLines="int"or editText.setMaxLines(int numOfLines) method if you want that to set how much the EditText will stretch. It'll do exactly what you need to do.