Home » Android » android – Leanback.DetailsFragment not scrolling as expected

android – Leanback.DetailsFragment not scrolling as expected

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a details fragment that is using a DetailsOverviewRow and FullWidthDetailsOverviewRowPresenter. When the page first loads the action buttons are selected. When I press down once, focus leaves the buttons and nothing else happens. When I press down a second time focus moves to a ListRow that is further down the page. I’m trying to figure out why the overview, or body as it’s called in the presenter, section doesn’t focus.

DetailsView initial state

DetailsView scrolled

Should there not be a second ‘state’ between the two screenshots where the overview/body is readable?

Possibly of note. The DetailsFragment isn’t declared in an activities xml, I’m changing fragments manually using FragmentTransactions. Also, the Fragment is instantiated using a static create method (source below).

Thanks in advance.

Activity xml

DetailsFragment java

How to&Answers:

I haven’t tried this example in particular, but from my time spent with Leanback support library, I learned that even though a lot of helpful stuff is indeed provided, a lot is not 😀

So I would try these things:

1) Make sure that something in the area you want visible is focusable. (Clickable elements should be focusable by default, but better check too) What I mean is that on the screenshot, there is just text, no buttons or editable content in that area. So when you press down, there is nothing to focus. What happens if you make the body TextView focusable?
(Yes, one would expect that the support library would take care of that, but that might not be the case.)

2) Find out what actually gets focused when you press down, since as you said, the focus leaves the buttons – but where does it go? (How to find out which view is focused?) You might have a “direction problem” somewhere. That is – the focus travels based on the view hierarchy tree, not based on what we see on the screen. In some cases, it is possible to skip some elements or get stuck somewhere by moving focus through an unexpected part of the view tree, that makes sense for the algorithm, but isn’t logical from the human perspective.

Answer:

The details presenter focus works this way :
1) First focus is given to Action buttons. Right/left nav press shifts the focus right/left between action buttons.

2) Down nav press from actions row shifts the focus from actions row to details row (individual details items itself are not focusable), this is achieved by shifting the Thumbnail anchoring position to further south.

3) Down nav press from details row shifts the focus from details row to related row.

So the details row gains focus by changing the anchoring position of Thumbnail image. Is your thumbnail image changing its anchoring position when pressing down from actions row?

Answer:

Hate to answer my own question. This was due to my failure to RTFM. I was creating the fragment UI after a network request completes. For the FullWidthDetailsPresenter to work properly it and the ClassPresenterSelector() should be initialized in the fragments onCreate() method.