Android - Expedia like Circular list view

I recently came across the launch screen of the expedia's Android app and the interface was quite nice. It looks like its a Grid view with each tiles having their own positions with the columns scrolling.


    Turns out that its not a GridView, instead two different ListViews placed next to each other. They have their own adapter providing the data and they have a reference to each other. This reference is what is being used to scroll the other list view when the user scrolls one of the lists. So how is the list view scrolled automatically? Well, its done via setSelectionFromTop. The logic is just to invoke it periodically via a Handler associated with the main thread. So far it makes sense, but how does the list view never reaches the end and instead just circles back to the first child?

    Well, its true that the list view didn't reach the end but its actually not displaying the first child, its actually displaying a new child view but the adapter is smart enough to inflate this new child view with the data corresponding to the first item. So, if the Flight list view had 5 destinations, the 6th child view is loaded with data (images and text) of the first destination and this is how circular behavior is achieved. So technically, the list view isn't endless and would at some time reach end of the list. The app's adapter probably uses a huge value for Adapter.getCount() to workaround and they probably expected that end users wouldn't stay in this launch screen for more than few seconds.

No comments: