Search code examples
androidandroid-recyclerviewrecyclerview-layoutleanback

How can I add SpanSizeLookup logic to VerticalGridView?


I'm developing an app for TV platform and I faced with a problem when default RecyclerView with GridLayoutManager can not handle focus control from DPAD correctly. It has the next problems:

  1. Focus is lost if list scrolled too fast
  2. If scrolled too fast focus jumps to the first position in the list
  3. Sometimes, when the DPAD down button is pressed, the focus is positioned at incorrect index (for example we have 4 columns, focus is on the first element and after DPAD down key is pressed it jumps to index 5, but it must jump to index 4)
  4. Focus is lost after restore intance state
  5. Many other small problems...

To avoid this behaviour I'm using VerticalGridView from leanback library with additional code and it works almost perfect - no any problems and it works with mouse and keyboard. The only thing that I can not do - set up SpanSizeLoockup as in "mobile" GridLayoutManager, because there is no such functionality. I need this to use header views in my list with span size for whole width in the row. The LayoutManager logic is too strange for understanding and I want to achieve this as easy as posible.

Question: How I can add SpanSizeLoockup functionality to VerticalGridView and do not break anything there?

The only thing that comes to mind - is to use custom view that represents one line in a list with a header, but this also can break focus logic.

Thanks in advance!


Solution

  • The short answer - it's not possible without hard modification of the source code.