开发者

ListView vs Nested Layout [Pros/Cons]

开发者 https://www.devze.com 2023-04-08 10:14 出处:网络
I\'m working on an android application and I have run into a decision that I can\'t decide on one way or another. I was hoping someone could shed some light on the common practices and any theory to b

I'm working on an android application and I have run into a decision that I can't decide on one way or another. I was hoping someone could shed some light on the common practices and any theory to back them.

Here's the issue:

I want to have a list of items with images and text li开发者_StackOverflow社区ke table...

Country -.-.-.-.-.-.- Pop -.- SqrMi

[img] US -.-.-.-.-.-.- xxx -.-.- xxxxx

Now the debate I'm having is whether or not to use a listview to display the data or instead nest a layout that is scrollable and just display the data that way.

Why would I even consider a nested layout? Flexibility. I can design the dividers, possibly throw in a couple graphs above/below the list. Vary the height of each of the list items (like what if I want to show a graph in one list item and no graph in the next), etc.

I'm not sure if I'm breaking the generally accepted methods here. Can anyone shed some light on this?


The only major problem you will have when using nested layouts is memory consumption. ListView reuses its children so it doesn't create more children then it can display at a single moment. This description is a little simplified but I hope it shows the purpose of the ListView. Also ListView implements its own fast scrolling so it doesn't have to measure all its children to determine its size. And ListViews use adapters to populate themselves with data. It's a nice and convenient way to obtain data.

On the other hand if you create a ScrollView with a lot of views inside it'll be slow, difficult to populate with data and it'll require a lot of memory to create all of the child views even if you don't ever see some of them.

And about flexibility of the ListView. You can store different types of view in a single ListView and you'll be able to vary the height of each of this views.


All the things you have described for your "nested layout" is achievable with ListView. Just use different types of rows, use headers/footers in adapter.

And as already Pixie said, ListView is much more memory efficient and faster.

0

精彩评论

暂无评论...
验证码 换一张
取 消