0

For understanding the structure I will be talking about, first see this example picture:

Multiple listviews

I need to show multiple ListViews in one fragment. The problem is when opening the given fragment, inflating the views takes quite a lot of time, because:

Each ListView inflates 3-5 items for itself, because neither of the ListViews have scrap views (yet).

So the fragment instantly inflates 10-30 instances of the same view, which can easily cause a 200-300ms long stutter, which is far from acceptable (the fragment has a show and hide animation).

My question would be, is there any way to speed up inflation (aside from using ViewHolders, simplifying hierarchy, and the usual things). Since the views are of the same type, there could be same global Recycler where the scrap views are stored, and outlive the life of the screen, which results in having scrap views when creating the ListView (looked into the ListView source code, and would require a lot of coding and understanding of the internals).

Since there quite a lot of apps having a similar structure, I'm curious how they solved (if they could have) the performance issue on inflation.

Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71

1 Answers1

0

You can use custom view as a list item to reduce the no of objects being instantiated.So if you are using 1 image view and 3-4 textviews for a list item,you can reduce the count to 1 by using a custom view...

If the design permits,you can put the entire 6 images as one custom view..

rupesh jain
  • 3,410
  • 1
  • 14
  • 22
  • The list should be scrollable, and can contain not only 6, but even 100 images in a row. – Daniel Zolnai Mar 30 '15 at 15:15
  • I understand that..but at a time only 6 will be visible..so you can build some logic to reuse the same object when the user scrolls the list..probably the custom list item object can store 8-9 images..you can figure out the number by checking the number of list items the system generate before recycling the views – rupesh jain Mar 30 '15 at 15:25
  • There would be no performance gain, and what if only 2 items fit the screen? (like on a phone). Also coding this would require too much effort. – Daniel Zolnai Mar 30 '15 at 15:58
  • There should be a performance gain because you are reducing the number of objects..however I agree it would require some coding efforts,however if performance is very critical i think it is worth it..for phone you would use a custom view with 2 images..basically you will have to make the custom view configurable to change the number of images... – rupesh jain Mar 30 '15 at 16:34
  • I am reducing the number of views, but I still have to inflate the same view hierarchy. Inflation time is not depending on number of views, but on complexity. – Daniel Zolnai Mar 30 '15 at 16:49
  • Since you are using only one custom view..it implies that complexity has reduced...You can profile both the approaches and check.... – rupesh jain Mar 30 '15 at 18:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74131/discussion-between-rupesh-jain-and-daniel-zolnai). – rupesh jain Mar 30 '15 at 19:02