Search code examples
androidanimationandroid-gallery

Autoadvancing gallery animation


I have a Gallery widget set up to auto advance every 10000ms. However the transition between views is instantaneous and I would prefer to have a transition.

My advancing method is like so:

private void tickerAdvance() {
    int selectedItemPosition = mTickerGallery.getSelectedItemPosition();
    if (selectedItemPosition + 1 == mTickerGallery.getCount()) {
        mTickerGallery.setSelection(0, true);
    } else {
        mTickerGallery.setSelection(selectedItemPosition + 1, true);
    }
}

I was under the impression that setting the animation to true would cause it to animate between states. In my XML I've also added animationDuration="500", however the transition still pops between states instantly.


Solution

  • The answer I came up with is that the Gallery API is terribly non-extensible. There are multiple package private or private methods that would unlock this functionality without a kludge including moveNext, FlingRunnable.startwithdistance, and scrollToChild. Alas, they are all unavailable.

    Instead the best answer I was able to come up with was to override setSelection to get all the behaviors I needed. In the setSelection method I reverse the deceleration algorithm to calculate a velocity for a calculated distance and then call onFling. This is a nasty kludge could be made a ton better by making any of the above methods protected or public (I can't fathom a reason why at least moveNext and scrollToChild shouldn't be).