装满后如何使Android EditText垂直展开 [英] How to make Android EditText expand vertically when full
本文介绍了装满后如何使Android EditText垂直展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个EditText
I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="@string/write_message"
android:textColorHint="@color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="@+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/primary_color"/>
当该框填充有用户输入的文本时,它会滚动到右侧以为更多文本腾出空间,我不喜欢这种行为,如果EditText框在需要更多空间时向上扩展,它会更喜欢它吗?有没有办法做到这一点?谢谢.
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
推荐答案
是的,这实际上涉及两件事:
Yes, this actually involves two things:
- 使
EditText
接受多行输入. - 它的高度随着添加的更多文本行而增加.
- Making the
EditText
accept multi-line input. - Having its height grow as more text lines are added.
因此,要实现这一点,您需要进行以下设置:
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(请注意 textMultiLine
与textImeMultiLine
).
(Be mindful of the difference between textMultiLine
and textImeMultiLine
).
完整的XML代码段将是:
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="@string/write_message"
android:textColorHint="@color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="@+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/primary_color"/>
这篇关于装满后如何使Android EditText垂直展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文