问题描述
我希望根据输入的文本大小动态增加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>
解决方法
请尝试:
<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>
,
您唯一要做的更改(两者都发生):
android:layout_height="wrap_content"
因为您要给它定高。将其更改为wrap_content,它应该可以工作。
您可以添加android:maxLines以限制其扩展程度。