1

When we want to change the view from Linear to Grid and viceversa we use recyclerView.setLayoutManager(layoutManager).

But how do we know that a new LayoutManager is set?

I've seen we have the method LayoutManager.onAttachToWindow(rv) and that this method is called inside setLayoutManager() but this means that we have to override that method and use our own LayoutManager.

Using addOnLayoutChangeListener() it works but it is called too often and for others purposes.

Is there a way to listen that a new Layout has been set?

Davideas
  • 3,226
  • 2
  • 33
  • 51
  • For what reason you are trying to achieve this ? – Ajay S Apr 17 '16 at 11:18
  • @TGMCians To use in combination with FastScroller, this custom library object should automatically update the inner reference to the LayoutManager (when this is changed from Linear to Grid and viceversa) to continue to scroll when the handle is dragged. I've found `addOnLayoutChangeListener()` but it is for others purposes, indeed it is called too often. – Davideas Apr 17 '16 at 16:28
  • 1
    Can you provide a link to your FastScroller implementation? You could work around this. I'm assuming you control when LayoutManager changes therefore you can switch it in FastScroller as well. FastScroller will either allow you to set LayoutManager manually or call `setRecyclerView` equivalent updating its internals and if that doesn't work try `setRecyclerView(null)` first. – Eugen Pechanec Apr 17 '16 at 17:15

0 Answers0