ScrollView vs ListView Performance

2019-07-31 15:06发布

问题:

I have this situation I wanted to discuss:

I have a listview that it's purpose is show 25 stores. For the design I want I have:

2 layouts, the first one has: 1 big photo of the store (downloaded from a database). 1 icon if the store belongs to the best rated stores list (that icon is on my app) 1 textview (downloaded string)

the second has: 3 textviews.(downloaded string)

Everytextview has a custom typeface.

As you can Imagine, this is a huge task for each item.

My main question is:

Wouldn't I get a much better performance if I downloaded everything and instead of making a listview I populate a scrollview with this data?

It might take a bit more to create the layout but probably it would be smoother scroll or am I wrong?

回答1:

You can do the same with ListView (download everything and display), but I don't think that "downloading everything" will actually bring any performance improvements (except you're talking about cache).

ScrollView will lead to much worse memory performance as you'll have to create and keep 25 views at once. On contrary, ListView reuse the same views while scrolling which will result in creating approximately as much views as it can fit on the screen.

With ScrollView, if dataset changes, you have to somehow repopulate your 25 views. In worst case recreating all views.

Moreover, going with ScrollView you'll have to deal with 25 big photos in memory at once which will probably give you nightmares for a few days.



回答2:

From my experience, if the number of elements in the list is less than 50 and the layout is not using too much memory, then you might be better off using a scrollview.

ListView is designed for much bigger dataset, and it's designed to reduce memory usage rather than performance. There are tons of work that Google put into it to optimize its performance. Together with viewholder pattern and modern hardware, and the perceived performance is close to fully populated scrollview.

But again, why need Listview if the dataset is small enough that doesn't affect memory usage? ListView is tricky to use when combined with fancy animation due to the underlying funky optimization done by Google.



回答3:

What I have learned from a similar problem is that the scrollview is smoother that the listview. My case was to opt one for the navigation drawer, because smooth inflation and scrolling in the drawer has direct impact on user experience. I first adopted the listview but it was by no means smooth. Then I found that found here that google developers use scrolview instead of listview for the drawer that works smooth for me either. But if lazy loading of the list items is what you require(not in my case), then you should go for listview.