Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TV RecyclerView focus interaction

I'm currently using a regular RecyclerView with GridLayoutManagerwith different spanCount depeding on the viewType for an Android TV app. All is working decent but I have 2 issues:

  1. If you long press the dpad down to scroll fast between the items sometimes the focus is lost to a view that isn't a child of the RecyclerView.
  2. How can I tell the RecyclerView to keep the current focused view in the center of the grid?

It seems that the issues listed are fixed by using the VerticalGridView from LeanBack library but the LayoutManger that it uses is internal and doesn't support spanCount.

like image 708
Tepes Lucian Avatar asked Aug 31 '16 11:08

Tepes Lucian


1 Answers

Recycler view works fine with android TV.Possible solutions you can include are:

1.add focusable and focusableInTouchode to view.Add focusListner through the code and request focus each time when the view is clicked.

2.To keep Recycler View focused item in the centre you have to override layout manager just like this example.

RecyclerView smoothScroll to position in the center. android

or

use layoutManager.scrollToPositionWithOffset(position,offset) where position-focused view position and offset is the recycler view width/2.

like image 194
Sharath kumar Avatar answered Sep 21 '22 12:09

Sharath kumar