Possible to jump straight to second view in ViewAnimator
Unfortunately, there is no built-in function to do that, but you can add this function, which does the job:
public static void setDisplayedChildNoAnim(ViewAnimator viewAnimator, int whichChild) {
Animation inAnimation = viewAnimator.getInAnimation();
Animation outAnimation = viewAnimator.getOutAnimation();
viewAnimator.setInAnimation(null);
viewAnimator.setOutAnimation(null);
viewAnimator.setDisplayedChild(whichChild);
viewAnimator.setInAnimation(inAnimation);
viewAnimator.setOutAnimation(outAnimation);
}
I looked around and waited for a response but I'm guessing it's not possible. So, in the absence of a better solution, set your ViewAnimator
's in/out animations to null when you want to jump straight to a particular child View
of your ViewAnimator
, as follows:
myViewAnimator.setInAnimation(null);
myViewAnimator.setOutAnimation(null);
myViewAnimator.setDisplayedChild(childIndex);
If anyone knows a better way - rather than playing with the ViewAnimator
's in/out animations - please share!