简体   繁体   中英

EditText textmultiline to display 3 lines by default

Android Studio 0.4.4

However, I can't seen to do that. As it always displays 1 line. Is there any way I can do this using the LinearLayout?

<TextView
    android:id="@+id/tvName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvPhone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<EditText
    android:id="@+id/etMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"
    android:hint="Enter your message"
    android:inputType="textImeMultiLine"
    android:minLines="3"
    android:gravity="top|left">

    <requestFocus/>
</EditText>

<Button
    android:id="@+id/btnSendMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Send Message"
    android:textSize="22sp"/>

<ImageView
    android:id="@+id/ivEmailPicture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="Picture of email being send"
    android:src="@drawable/email"/>

Add this to your EditText's xml code.

android:lines="3" 

I'm not sure if it will solve your problem but refering to the documentation it should.

You need to change the "android:lines" value of the EditText: Your code should look like this:

<TextView
    android:id="@+id/tvName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvPhone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<EditText
    android:id="@+id/etMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"
    android:hint="Enter your message"
    android:inputType="textImeMultiLine"
    android:lines="3"
    android:minLines="3"
    android:gravity="top|left">

    <requestFocus/>
</EditText>

<Button
    android:id="@+id/btnSendMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Send Message"
    android:textSize="22sp"/>

<ImageView
    android:id="@+id/ivEmailPicture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="Picture of email being send"
    android:src="@drawable/email"/>

    <requestFocus/>
</EditText>

<Button
    android:id="@+id/btnSendMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Send Message"
    android:textSize="22sp"/>

<ImageView
    android:id="@+id/ivEmailPicture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="Picture of email being send"
    android:src="@drawable/email"/>

Good luck! :)

android:lines="3" android:ellipsize="end"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM