Android的自动换行的EditText文本 [英] Android Word-Wrap EditText text
问题描述
我一直在试图让我的EditText框自动换行,但似乎无法做到这一点。
我处理过的要复杂得多的问题,同时开发Android应用程序,这似乎像它应该是一个简单的过程。
然而,问题仍然存在,我有一个大的文本框,只允许我在一行中输入文字,跨继续直行,水平滚动,我输入文字。
下面是XML code从我的布局文件中的EditText对象。
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
机器人:ID =@ + ID / myWidget48
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
的xmlns:机器人=http://schemas.android.com/apk/res/android
>
<滚动型
机器人:ID =@ + ID / myScrollView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
>
<的LinearLayout
机器人:ID =@ + ID / widget37
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
>
<的EditText
机器人:ID =@ + ID / txtNotes
机器人:layout_width =300像素
机器人:layout_height =120px
机器人:滚动条=垂直
机器人:TEXTSIZE =18sp
机器人:重力=左
机器人:layout_marginTop =10dip
机器人:inputType =textCapSentences
>
< /的EditText>
< / LinearLayout中>
< /滚动型>
< / LinearLayout中>
另外寻找问题的根源,我找到了解决办法。如果安卓inputType
时,则textMultiLine必须用于启用多行支持。此外,使用inputType取代了code 安卓SINGLELINE =假
。如果使用inputType,然后,再次重申,textMultiLine必须使用或的EditText对象将只包含一条线,没有自动换行。
编辑:谢谢雅各Malliet 查找有关此提供更多好的建议。他建议布尔scrollHorizontally属性设置为false,'机器人:scrollHorizontally =假
。
示例XML code:
<的EditText
机器人:ID =@ + ID / edtInput
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:inputType =textCapSentences | textMultiLine
机器人:MAXLINES =4
机器人:最大长度=2000
机器人:提示=@字符串/ compose_hint
机器人:scrollHorizontally =FALSE/>
I have been trying to get my EditText box to word wrap, but can't seem to do it.
I have dealt with much more complicated issues while developing Android applications, and this seems like it should be a straight-forward 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.
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>
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.
Edit: Thank you Jacob Malliet for providing further good advice on this. He suggested to set the boolean scrollHorizontally property to false, 'android:scrollHorizontally="false"'
.
Example XML code:
<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的自动换行的EditText文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!