的EditText自动换行换行、EditText

由网友(时间煮雨)分享简介:我有这样的布局:我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin" >

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

我要当用户进入比其适合单行更多的文本是,在的EditText 包装线,增加了它的高度自动显示了不恰当的文字在下一行。在的EditText 不应该是滚动的水平。

What i want is when the user enters more text than which fits into a single line, the EditText wraps the line, increases it height automatically and shows the not fitting text in the next line. The EditText should not be scrollable horizontally.

我阅读了大量与此相关的问题,但他们没有帮助。目前,的EditText 上面不换行,并可以水平滚动。我在Android 4.2和4.4的测试。

I read lots of questions related to this, but none of them helped. Currently the EditText above does not wrap the lines, and can be scrolled horizontally. I tested on Android 4.2 and 4.4.

编辑:补充完整布局

EDIT2:

对不起,这是我的错。我编程更改输入型我code:

Sorry, this is my fault. I change the input type programatically in my code:

mEditText.setInputType(mInputTypes.get(question.getType()));

因此​​,与这条线,我已经重写从XML输入类型。我修改了code,以及输入类型确实有效。

推荐答案

我已删除了所有不必要的属性,把只要求属性的android:MAXLINES =20,

I have removed all unnecessary attributes and put only required attribute android:maxLines="20",

所以它看起来像这样,

    <EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:maxLines="20" />
阅读全文

相关推荐

最新文章