Android maxLines 和 minLines 属性在 XML 中不起作用 [英] Android maxLines and minLines attributes not working in XML

查看:56
本文介绍了Android maxLines 和 minLines 属性在 XML 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 文件,其中包含具有以下属性的 EditText:

I have an XML file which contains an EditText with these attributes:

<EditText
        android:id="@+id/et_firstname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/view_margin_below"
        android:hint="@string/et_firstname"
        android:maxLength="20"
        android:minLines="1"
        android:maxLines="1" />

由于 android:singleline 已被弃用,我寻找了另一个选项并找到了这些属性,但它们不起作用.我可以输入任意多的换行符.

Since android:singleline is deprecated, I looked for another option and I found these attributes, but they aren't working. I am allowed to enter as many newlines as I want.

推荐答案

就像 API 中描述的 minLinesmaxLines 属性一样,你必须使用 属性android:inputType="textMultiLine" 也是:

Like described in API for minLinesand maxLines attribute, you have to use the attribute android:inputType="textMultiLine" too:

API:

android:maxLines

android:maxLines

使 TextView 最多有这么多行高.当用于可编辑文本时,inputType 属性的值必须为结合 maxLines 属性的 textMultiLine 标志申请.

Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

android:minLines

android:minLines

使 TextView 至少有这么多行高.当用于可编辑文本,inputType 属性的值必须与要应用的 minLines 属性的 textMultiLine 标志.

Makes the TextView be at least this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the minLines attribute to apply.

<EditText
        android:id="@+id/et_firstname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/view_margin_below"
        android:hint="@string/et_firstname"
        android:maxLength="20"
        android:minLines="1"
        android:inputType="textMultiLine"
        android:maxLines="1" />

所以我想,你只需要添加这个属性.

So I guess, You just have to add this attribute.

为避免误解:这些属性的行为将允许输入多行,但只会显示一行.但是,它是可滚动的,因此如果您输入更多行,则可以上下滚动以查看其他行.

To avoid misunderstandings: The behaviour of these attributes will allow to enter multiple lines, but it will be only shown one line. BUT, it´s scrollable, so if you put in some more lines, you can scroll up and down to see the other lines.

这在 singleLine 的 API 中有说明.minLinesmaxLines 工作类似:

This is stated in API for singleLine. minLinesand maxLines work similar:

将文本限制为一条水平滚动的行而不是让它包裹在多行上

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines

这篇关于Android maxLines 和 minLines 属性在 XML 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆