我一直在尝试让我的 EditText 框自动换行,但似乎无法做到.
I have been trying to get my EditText box to word wrap, but can't seem to do it.
我在开发 Android 应用程序时处理了更复杂的问题,这似乎应该是一个简单的过程.
I have dealt with much more complicated issues while developing Android applications, and this seems like it should be a straightforward process.
但是,问题仍然存在,我有一个大文本框,它只允许我在一行上输入文本,继续直行,在我输入文本时水平滚动.
However, the issue remains, and I have a large text box that is only allowing me to enter text on one line, continuing straight across, scrolling horizontally as I enter text.
这是我的布局文件中 EditText 对象的 XML 代码.
Here is the XML code for the EditText object from my layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/myWidget48"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:id="@+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/txtNotes"
android:layout_width="300px"
android:layout_height="120px"
android:scrollbars="vertical"
android:textSize="18sp"
android:gravity="left"
android:layout_marginTop="10dip"
android:inputType="textCapSentences"
>
</EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
除了找到问题的根源,我找到了解决方案.如果使用 android:inputType
,则必须使用 textMultiLine 来启用多行支持.此外,使用 inputType 取代了代码 android:singleLine="false"
.如果使用 inputType,那么重申一下,必须使用 textMultiLine,否则 EditText 对象将仅包含一行,没有自动换行.
Besides finding the source of the issue, I found the solution. If android:inputType
is used, then textMultiLine must be used to enable multi-line support. Also, using inputType supersedes the code android:singleLine="false"
. If using inputType, then, to reiterate, textMultiLine must be used or the EditText object will only consist of one line, without word-wrapping.
感谢Jacob Malliet就此提供进一步的好建议.他建议将 boolean scrollHorizontally 属性设置为 false,'android:scrollHorizontally="false"'
.
Thank you Jacob Malliet for providing further good advice on this. He suggested to set the boolean scrollHorizontally property to false, 'android:scrollHorizontally="false"'
.
示例 XML 代码:
<EditText
android:id ="@+id/edtInput"
android:layout_width ="0dip"
android:layout_height ="wrap_content"
android:layout_weight ="1"
android:inputType="textCapSentences|textMultiLine"
android:maxLines ="4"
android:maxLength ="2000"
android:hint ="@string/compose_hint"
android:scrollHorizontally="false" />
这篇关于Android Word-Wrap EditText 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!