Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the xml attribute singleLine deprecated or not in Android?

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" /> 

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:

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

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?

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

like image 536
Suragch Avatar asked May 04 '15 11:05

Suragch


People also ask

Why was the singleline attribute deprecated in Android?

The reason of the deprecation is for its bad performance. Anyway the singleLine attribute will not be removed because it's still the only way to make some effects that android:maxLines can't make: This will produce a scrolling horizontal text on one line if the text is selected.

Is it possible to remove the singleline attribute in Android Studio?

android:singleLine is deprecated since API 3, you have to use android:maxLines instead (in your case android:maxLines="1" ). The reason of the deprecation is for its bad performance. Anyway the singleLine attribute will not be removed because it's still the only way to make some effects that android:maxLines can't make:

What is the difference between singleline and maxlines in Android?

The android:singleLine attribute has been deprecated since API Level 15. You can achieve the same behaviour by using android:maxLines, which allows you to specify an arbitrary number of lines. This is superior to android:singleLine, which restricts you to only allowing one line.

What is xmlxml in Android?

XML in Android: Basics And Different XML Files Used In Android XML stands for Extensible Markup Language. XML is a markup language much like HTML used to describe data. XML tags are not predefined in XML.


1 Answers

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.

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

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.

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.

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

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.

like image 100
ugo Avatar answered Sep 24 '22 15:09

ugo