简体   繁体   中英

Android Edittext Multiline - Fix Line Height

<style name="MessageInput">
    <item name="android:gravity">top</item>
    <item name="android:singleLine">false</item>
    <item name="android:lines">4</item>
    <item name="android:minLines">4</item>
    <item name="android:minHeight">10dp</item>
    <item name="android:maxLines">4</item>
    <item name="android:inputType">textMultiLine</item>
    <item name="android:scrollHorizontally">false</item>
    <item name="android:background">?android:attr/colorBackground</item>
    <item name="android:layout_weight">1</item>
    <item name="android:textSize">18sp</item>
    <item name="android:focusable">true</item>
    <item name="android:isScrollContainer">true</item>
    <item name="android:padding">10dp</item>
    <item name="android:textColor">?android:attr/textColor</item>
    <item name="android:paddingTop">40dp</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:lineSpacingExtra">18dp</item>
    <item name="android:lineSpacingMultiplier">1</item>
</style>

This is the style I am using in the EDITTEXT but my result shows the initial display as multiple line edittext with text shown in multiple lines spaced correctly. But the problem is, once I start adding texts and lines, the space ot the line height is not as previously shown. I need an edittext with constant LINE HEIGHT of max 4 lines, or any number of lines.

enter image description here enter image description here

This is a sample edittext...with 1st 3 lines being initially shown by default, and its shown nicely. But if i press enter key, the line spacing is gone and it displays texts in the above way.


I am actually using a custom edittext to display under-lines. Like below:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <jp.softbank.wallet.view.LinedEditText
        android:id="@+id/edittext_message"
        style="@style/MessageInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Try this:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:lines="4"
    android:minLines="4"
    android:maxLines="4"
    android:gravity="top" />

OUTPUT

在此处输入图片说明

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