android - 如何在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>
解决方案
请试试这个:
<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>
推荐阅读
- python - 如何读取目录中文件的文件内容并将副本创建到新目录中?
- python - 以 .py 结尾的文件被视为 .txt 文件,而不是在 python 空闲时启动
- python - Darknet YoloV4 空预测
- flutter - Flutter InAppWebView 不允许文本字段中包含非英文内容
- ruby-on-rails - Rails action params[:user] 未提供如何返回错误
- python - 在 __init__.py 文件中导入 .c、.cpp、.hpp、.pyx 模块
- reactjs - 异步类组件函数到函数组件函数。我在这个钩子中使用扩展运算符吗?
- python - 如何检查字符串是否仅包含不可打印的字符和空格?
- javascript - 如何在一页上使用 Google Captcha for 2 Django Form
- android - 从 AnimatorVectorDrawable 只为一个目标设置动画