1

I have a Vertical RecyclerView, and this vertical RecyclerView's each item contains Horizontal RecyclerView. so I have done this and working fine except the performance factor, when I scroll the Vertical RecyclerView the vertical list flickers and gives a bad behaviour. I am setting Adapter for horizontal RecyclerView is inside Vertical RecyclerView so each time scrolls I am creating a new adapter and setting the data, actually this causes the performance. Is there any way to optimize this ?

Code

onBindViewHolder(){
  setHorizontalList(items, horizontalolder);
}

setHorizontalList(ArrayList<Item> items, HorizontalHolder holder){
  MyAdapter adapter = new MyAdapter();
  adapter.setData(items);
  holder.recyclerView.setAdapter(adapter);
  holder.recyclerView.setLayoutManager(new LinearLayoutManager(mContext,
                    LinearLayoutManager.HORIZONTAL, false));
  holder.recyclerView.setHasFixedSize(true);
}
droidev
  • 7,352
  • 11
  • 62
  • 94
  • Have you found a solution to this? I have seen similar problem where my inner item background is not properly wrap_content as it should be. – RobGThai Nov 26 '16 at 18:39
  • Yes. I have created adapter for the second RecyclerView inside ViewHolder class. So that it won't create new instances. – droidev Nov 27 '16 at 18:06
  • I have done the same but my background goes wonky. Do you mind taking a quick look on my issue? http://stackoverflow.com/questions/40823501/recyclerview-gridlayoutmanager-item-resize-to-last-item – RobGThai Nov 27 '16 at 19:49

1 Answers1

0

The performance is bad because you set setHasFixedSize(boolean) to true, this will cause every nested horizontal RecyclerView to load all its views when it becomes visible in the vertical RecyclerView. Setting the fixed size to true is ussualy used to make a RecyclerView wrap its content. But to wrap its own content he has to know the size of its content, therefore he has to create all views when becoming visible (to know his max height and width).

Best way to optimize your nested RecyclerViews is to not set the fixed size to true.But this will probably cause your nested RecyclerViews to not be shown completely, because it does not know his height (since different views in a RecyclerView can have different heights). One way to solve this is by using a hardcoded height or make your own CustomRecyclerView class that extends RecyclerView and override the measurements methods.

Jeffalee
  • 1,080
  • 1
  • 7
  • 15
  • not working, the issue is because of creating Adapters inside onBindViewHolder(), thats what i need to optimize. – droidev May 18 '16 at 11:54