我有这样的布局:
<?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
不应水平滚动。
我读了很多与此相关的问题,但没有一个有帮助。目前EditText
上面不换行,并且可以水平滚动。我在 Android 4.2 和 4.4 上进行了测试。
EDIT:添加了完整的布局。
EDIT2:
抱歉,这是我的错。我在代码中以编程方式更改输入类型:
mEditText.setInputType(mInputTypes.get(question.getType()));
因此,通过这一行,我覆盖了 xml 中的输入类型。我修改了代码,并且multiLine
输入类型确实有效。
我删除了所有不必要的属性,只放置必需的属性 android:maxLines="20",
所以看起来像这样,
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="20" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)