加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml属性singleLine是否已弃用或不在Android中?

发布时间:2020-12-16 22:36:35 所属栏目:百科 来源:网络整理
导读:singleLine是/用于TextView和EditText的xml布局文件中,如下所示: TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" / Some people on SO说singleLine已被弃用,而other people仍然建议使用
singleLine是/用于TextView和EditText的xml布局文件中,如下所示:
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true" />

Some people on SO说singleLine已被弃用,而other people仍然建议使用它。有时甚至似乎有必要使用时maxLines =“1”不工作。 (参见here,here和here)

文档应该是去回答这个问题的地方,对吧? Here,they say:

This constant was deprecated in API level 3.

This attribute is
deprecated. Use maxLines instead to change the layout of a static
text,and use the textMultiLine flag in the inputType attribute
instead for editable text views (if both singleLine and inputType are
supplied,the inputType flags will override the value of singleLine).

但是,in the TextView docs没有指示它已被弃用,对于android:singleLinesetSingleLinesetTransformationMethod来说。相同的TextView文档通过比较指出,其他的东西,如STATUS_BAR_HIDDEN和fitSystemWindows已经被弃用。所以是singleLine的deprecation一个遗漏,是“不推荐”,还是什么?

这个问题已经是previously asked before,但不是问题的主要焦点(并没有回答)。

我认为你的问题的答案已经在SO posts you linked to之一。不幸的是,单线的废弃不是一个黑白的事情。

它已被弃用,但它不会随时随地。

它已被弃用,因为它的性能相对于其后继者maxLines较差。它使用SingleLineTransformationMethod替换在TextView中放置的字符串中的换行符和回车符,与maxLines不同,maxLines根据行数调整TextView的高度,不替换字符串。

这种替换字符的方法也意味着singleLine可以是break in unexpected ways(例如,如果你使用自定义字体)。正是这些性能和可靠性问题导致其弃用。

然而,它不会去任何地方,因为SO post你链接到状态,它仍然被许多旧的Android应用程序使用,它仍然是有用的(例如,当你想显示整个文本在一行,并忽略回车和换行)。

请注意,弃用并不一定意味着API会消失。它只是意味着它的使用被劝阻,但可能被允许。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读