問(wèn)題描述
我一直在嘗試讓我的 EditText 框自動(dòng)換行,但似乎無(wú)法做到.
I have been trying to get my EditText box to word wrap, but can't seem to do it.
我在開(kāi)發(fā) Android 應(yīng)用程序時(shí)處理了更復(fù)雜的問(wèn)題,這似乎應(yīng)該是一個(gè)簡(jiǎn)單的過(guò)程.
I have dealt with much more complicated issues while developing Android applications, and this seems like it should be a straightforward process.
但是,問(wèn)題仍然存在,我有一個(gè)大文本框,它只允許我在一行上輸入文本,繼續(xù)直行,在我輸入文本時(shí)水平滾動(dòng).
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 對(duì)象的 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>
推薦答案
除了找到問(wèn)題的根源,我找到了解決方案.如果使用 android:inputType
,則必須使用 textMultiLine 來(lái)啟用多行支持.此外,使用 inputType 取代了代碼 android:singleLine="false"
.如果使用 inputType,那么重申一下,必須使用 textMultiLine,否則 EditText 對(duì)象將僅包含一行,沒(méi)有自動(dòng)換行.
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就此提供進(jìn)一步的好建議.他建議將 boolean scrollHorizo??ntally 屬性設(shè)置為 false,'android:scrollHorizo??ntally="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" />
這篇關(guān)于Android Word-Wrap EditText 文本的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!