I'm trying to convert the RealViewSwitcher based on the work from Marc Reichelt into one that is backed up with a ListAdapter. A horisontally scrollable ViewGroup that contains multiple views, where one is visible at a time.
My current solution adds at the most 3 views to the ViewGroup at a time. One (in the middle) which is visible and two buffered views, one on each side. When a user scrolls, say to the right, the left-most View is removed and a new View is added to the right. In order for the ViewGroup to be scrollable both to the left and right I need to always focus on the View in the middle. So, when a View is being switched, I arrange the Views correctly and sets focus on the View in the middle. The issue with this approach is that it suffers with a flickering effect when the Views are arranged. Let me illustrate the issue with a picture I drew:
A, B and C are three different views in my ViewGroup (the ListAdapter backing up the ViewGroup contains of more elements though, but only three are loaded at a time). The larger rectangle represents where focus is at the moment. I scroll to the left and at (3) I snap to the destination which is the left-most View. Then I re-arrange the view. I.e. Add a new view X to the left and remove View C to the right, placing A in the middle. Finally I center on the View in the middle (A) which was the one I scrolled to from the beginning.
So, when I do the last re-arranging of Views and center on A in the middle, the content of the View which was previously in the middle (B in this case) flashes a few milliseconds causing a flicker effect which is uncalled-for. Any ideas of how I can go around that?
Problem solved. The issue seems to be related to changing the childs in a ViewGroup and then call the scrollTo method. If I instead use a Scroller to move to the right view/child, the flickering issue disappears.