首页 > 解决方案 > 如何在android中动态增加EditText的大小?

问题描述

我希望 EditText 的高度根据输入的文本大小动态增加。

就像Whatsapp一样。

这就是我现在正在做的事情!

 <LinearLayout
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="44dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="8dp"
    android:orientation="horizontal">


    <EditText
        android:textSize="15dp"
        android:textColor="#000000"
        android:hint="Enter New Note"
        android:textColorHint="#8B111111"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:imeOptions="actionDone"
        android:layout_marginTop="8dp"
        android:contentDescription="Enter Input Here"
        android:layout_marginBottom="8dp"
        android:id="@+id/editextNew"/>

</LinearLayout>

标签: androidandroid-studioandroid-layoutandroid-edittext

解决方案


请试试这个:

 <LinearLayout
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="8dp"
    android:orientation="horizontal">


    <EditText
        android:textSize="15dp"
        android:textColor="#000000"
        android:hint="Enter New Note"
        android:maxLines="40"
        android:lines="20"
        android:textColorHint="#8B111111"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:imeOptions="actionDone"
        android:layout_marginTop="8dp"
        android:contentDescription="Enter Input Here"
        android:layout_marginBottom="8dp"
        android:id="@+id/editextNew"/>

</LinearLayout>

推荐阅读