Skip to content

Challenges of creating a looping LayoutManager

Beka Westberg edited this page Dec 23, 2019 · 1 revision

This page is meant to document some challenges that should be kept in mind when contributing to the Looping Layout Manager project.

1. Child indices vs adapter indices

Views in a layout manager have two kinds of indices. One (the child index) is associated with the position of the view on screen, and the other (the adapter index) tells us which piece of adapter data the view is assoicated with.

Sadly LayoutManagers can only loop through views based on their child index, so you need to make sure you properly convert between the two.

For more information about child indices vs adapter indices, see the directional conversion page.

2. Multiple views can be associated with the same adapter index

Because the LoopingLayoutManager loops, we can sometimes have more than one view on screen associated with the same adapter index. Specifically if the total size of all the views is less than the size of the recycler.

And because of this, if we're trying to find a view associated with a given index we need a way to decide between two (or more) views. This logic is encapsulated in a ViewPicker.

3. Scrolling works in either direction

If you want to make a certain view visible on screen, you can scroll in either direction to find it. This is convenient for users, but makes it harder to implement things like programmatic smooth scrolling, because you have to decide programmatically which direction you want to go in. The logic for deciding is encapsulated in a DirectionDecider.

Clone this wiki locally