How to Make EditText Box Height Expand

前端 未结 6 896
眼角桃花
眼角桃花 2020-12-12 20:11

Here is my layout:




        
相关标签:
6条回答
  • 2020-12-12 20:43

    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.

    0 讨论(0)
  • 2020-12-12 20:49

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

    &

    android:lines="5"
    

    This did the trick for me inside ConstraintLayout

    0 讨论(0)
  • 2020-12-12 20:51

    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"/>
    
    0 讨论(0)
  • 2020-12-12 20:53

    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"/>
    
    0 讨论(0)
  • 2020-12-12 20:54

    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

    0 讨论(0)
  • 2020-12-12 21:01

    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" />
    
    0 讨论(0)
提交回复
热议问题