2

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?

Fattie
  • 27,874
  • 70
  • 431
  • 719
Rahul Rastogi
  • 4,486
  • 5
  • 32
  • 51
  • 1
    Why you don't use async image download mechanism ? – βhargavḯ Dec 20 '13 at 04:48
  • please post your code.... – dipali Dec 20 '13 at 04:50
  • 1
    why don't use a custom lazy load library as mentioned in this answer? http://stackoverflow.com/a/8562313/1979347 – Rohan Kandwal Dec 20 '13 at 04:53
  • 1
    Actually, I am inflating each post row and adding to my main linear layout that is itself in a scroll view. So when the main linear layout height exceed, it starts scrolling due to scroll view. So i am having the listView functionality with linearlayouts. I want to know that will there be any benefit of using the listview instead of nested linearlayouts Or any disadvantage of using such linearlayouts. Since, the number of rows inflated can be upto 200. – Rahul Rastogi Dec 20 '13 at 05:01
  • Possible duplicate of [ListView vs LinearLayout](http://stackoverflow.com/questions/3483809/listview-vs-linearlayout) – Ciro Santilli OurBigBook.com Feb 08 '16 at 21:27

2 Answers2

3

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

Khay
  • 981
  • 1
  • 10
  • 22
2

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.

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • Hey Anup -- **putting aside** the performance factor. Let's say we are talking about **short lists only** . So, only ten or twenty items, let's say .. imagine perhaps a popup selector of some sort. So, the whole thing is less than one or two screen heights, we'll say. **In that case** I'm really curious about which "is better" -- is there any downside to just filling a LinearList with little views? What's the feeling among Android pros? – Fattie May 22 '14 at 11:14
  • 1
    In that case, I personally feel it's better to use just regular views without a ListView. – Anup Cowkur May 22 '14 at 11:20
  • @AnupCowkur:Hi, how about if I have no a few child views no less than 10, but each view(item) have a lot of sub views? – hguser Jul 29 '14 at 00:21