我一直在尝试让我的 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模板网!
EditText:禁用文本选择处理程序单击事件上的粘贴EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本选择处理程序单击事件上的粘贴/替换菜
2.3 上带有完成 SoftInput 操作标签的多行 EditTextMultiline EditText with Done SoftInput Action Label on 2.3(2.3 上带有完成 SoftInput 操作标签的多行 EditText)
如何在 Android 中检测向左或向右滑动?How to detect the swipe left or Right in Android?(如何在 Android 中检测向左或向右滑动?)
防止在Android中的屏幕旋转对话框解除Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋转对话框解除)
如何处理 ImeOptions 的完成按钮点击?How do I handle ImeOptions#39; done button click?(如何处理 ImeOptions 的完成按钮点击?)
您如何将 EditText 设置为仅接受 Android 中的数值How do you set EditText to only accept numeric values in Android?(您如何将 EditText 设置为仅接受 Android 中的数值?)