是XML属性SINGLELINE depricated或者未Android的? [英] Is the xml attribute singleLine depricated or not in Android?

查看:1738
本文介绍了是XML属性SINGLELINE depricated或者未Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SINGLELINE 是在XML布局文件中使用/为的TextView 的EditText 类似以下内容:

singleLine is/was used in xml layout files for TextView and EditText something like the following:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true" />

有人的上这么说 SINGLELINE 是德precated,而其他人还是建议使用它。有时甚至似乎有必要时, MAXLINES =1不起作用使用。 (请参见 href=\"http://stackoverflow.com/a/30029722/3681880\">,这里< /一>和<一href=\"http://stackoverflow.com/questions/24351698/textviews-ellipsize-not-working-on-maxlines-1\">here)

Some people on SO say singleLine is deprecated, while other people still suggest using it. Sometimes it even seems necessary to use when maxLines="1" doesn't work. (see here, here, and here)

该文档应该去回答这个问题的地方,对不对? 在这里,他们说:

The docs should be the place to go to answer this question, right? Here, they say:

此常数德$ P $在API级别3 pcated。

这是属性
  德precated。使用 MAXLINES ,而不是改变一个静态的布局
  文本,并使用 textMultiLine 国旗在inputType下属性
  不是为可编辑的文本视图(如单线和inputType下都是
  提供时,inputType下标志将覆盖SINGLELINE的值)。

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).

不过,在TextView的文档 ,没有任何迹象表明它是德precated,无论是<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine\"><$c$c>android:singleLine或<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29\"><$c$c>setSingleLine或<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#setTransformationMethod%28android.text.method.TransformationMethod%29\"><$c$c>setTransformationMethod.同样TextView的文档,通过比较,做到国家,其他的东西像 STATUS_BAR_HIDDEN fitSystemWindows 是德precated。所以是 SINGLELINE 德precation遗漏,被它理解过程precated,还是什么?

However, in the TextView docs, there is no indication that it is deprecated, either for android:singleLine or for setSingleLine or for setTransformationMethod. The same TextView docs, by comparison, do state that other things like STATUS_BAR_HIDDEN and fitSystemWindows are deprecated. So is the singleLine deprecation an omission, was it "undeprecated", or what?

此问题已<一个href=\"http://stackoverflow.com/questions/7026121/androidsingleline-of-textview-is-nolonger-in-the-de$p$pcated\">$p$pviously 问过,但不是问题的主要焦点(并没有回答)。

This question has been previously asked before but was not the main focus of the question (and was not answered).

推荐答案

我想回答你的问题已经在做的一个的您链接到的帖子。不幸的是,去precation singleLines 不是一个非黑即白的问题。

I think the answer to your question is already in one of the SO posts you linked to. Unfortunately, the deprecation of singleLines is not a black-or-white matter.

它的的德precated,但它的的很快去任何地方。

It is deprecated, but it is not going anywhere anytime soon.

据德precated因为其性能差,相对于它的后继者, MAXLINES 。它使用<一个href=\"https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/text/method/SingleLineTransformationMethod.java\"相对=nofollow> SingleLineTransformationMethod 代替换行符和回车在你将字符串的的TextView 不像 MAXLINES ,其中只是调整高度的的TextView 基于行的数量并不做任何字符串替换。

It was deprecated because its performance is poor, relative to its successor, maxLines. It uses SingleLineTransformationMethod to replace newlines and carriage returns in the String you place in the TextView, unlike maxLines, which "just" adjusts the height of the TextView based on the number of lines and does no String replacing.

替换字符这种方法也意味着 SINGLELINE 意想不到的方式打破(例如,如果您使用自定义字体)。正是这些性能和可靠性问题,导致其德precation。

This method of replacing characters also meant that singleLine could break in unexpected ways (e.g. if you use custom fonts). It was these performance and reliability issues that led to its deprecation.

然而,这是不会去任何地方,因为,因为在post您链接到的状态,它仍然是在使用许多旧的Andr​​oid应用程序,的它仍然是有用有时(例如,​​当你想显示在一行中的全部的文本,而忽略回车符号和换行符)。

However, it is not going anywhere because, as the SO post you linked to states, it is still in use by many old Android applications, and it is still useful sometimes (e.g. when you want to show the entire text on one line and ignore carriage-returns and newlines).

请注意,德precation并不一定意味着一个API会消失。它只是意味着它不鼓励使用,但可容许的。

Do note that deprecation does not necessarily mean that an API is going away. It just means that its use is discouraged, but may be permitted.

这篇关于是XML属性SINGLELINE depricated或者未Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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