Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does android:singleLine="true" make ListView scrolling very laggy?

I've noticed that android:singleLine="true", if used in the TextView of Listitem in ListView, makes scrolling very laggy. Though I've found an alternative android:maxLines="1", I'm very curious to know why android:singleLine="true"makes scrolling very laggy and even if it's laggy, why is android still using that ?

like image 987
jimmy0251 Avatar asked Jun 15 '13 15:06

jimmy0251


1 Answers

It seems that these 2 functions are actually not giving exactly the same results.

According to an interesting topic created on this blog by Radley Marx, singleLine is mostly deprecated now but can still be useful in some cases because it will not consider the carriage returns and gather the maximum of text in the single line:

The biggest advantage is that singleLine would ignore carriage returns (\n) and place all text on a single line, sometimes even squeezing text together. MaxLines doesn’t bother.

Finally he concludes:

Although singleLine is deprecated, it’s still in heavy use in older Android apps on old Android phones so it’s not really going away. But it has been long abandoned and tends to break in unexpected ways. Use maxLines whenever you can and singleLine only when you must.

Then if you check Android documentation about both methods: singleLine and maxLines, you can see that the first one is handled by a text TransformationMethod that would explain I guess why it is much slower than the second one.

like image 156
Yoann Hercouet Avatar answered Nov 12 '22 11:11

Yoann Hercouet