Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

performance - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...