问题
I am downloading a lot of images and text (Just like facebook posts) from server.
So as the listview is scrolled it blinks while creating recycled views. So i want to use multiple linearlayouts for each of the post inside my main linear layout.
In this case, Will there be any scrolling performance or memory consumption issue? Please help?
回答1:
You should not use a bunch of LinearLayouts as a replacement for a ListView.
ListViews do something called as View Recycling so that at any one time only the number of views that the user can actually see are held in memory. The rest of the views are created and discarded as and when the user scrolls up/down.
For instance, if your screen size is such that you can only see 10 rows at a time, then only 10-15 rows of the ListView will be in memory at any one time depending on the specific implementation.
If your replace your ListView with 200 LinearLayouts instead, then you will be holding 200 ViewGroups in memory. This can cause sluggish performance or cause the application to crash due to an OutOfMemoryError.
For more tips on ListView performance improvement, see this great post by Lucas Rocha.
回答2:
Well certainly there will be an performance issue Since listview creates and discards the list items not in focus , like out of 200 only the ones that are on screens (say 10) are in memory , where as in linear layout all 200 will have to be withhold in the memory ,and this is memory from the heap not the stack , thus it will make you phone suffer if the application is kept running and will get FORCE CLOSE due to out of memory problem.
You can also make your linear layout make discard the items not in focus , but again even after so much effort it will be same as the list view , so i wouldnt suggest to do so and rather straight away use list view
来源:https://stackoverflow.com/questions/20696438/can-i-use-nested-linearlayouts-instead-of-list-view-for-a-big-list