I have an infinite and autoscrolling view pager with 3 pages (views, not fragments). Using ObjectAnimator
I set up a dummy animation like so:
valueAnimator.setRepeatMode(ObjectAnimator.RESTART);
valueAnimator.setRepeatCount(ObjectAnimator.INFINITE);
valueAnimator.setDuration(1500);
and in onAnimationRepeat
, I use setCurrentItem(nextItem, true)
to move to the next page. However if I sit and wait at this screen then UI performance gets lower and lower after 10 or so page changes (Using TinyDancer I have observed FPS dropping to 20 from 60).
However, changing the line to setCurrentItem(nextItem, false)
(setting smoothScroll
to false) the performance drop is eliminated.
Is there something about calling setCurrentItem
multiple times that can cause this? Can I tweak the smoothScroll
behaviour to fix this? Again, I have at most 5 views loaded in this pager at any time, and I have observed memory usage staying still when watching FPS drop.
It's most likely got to do with views that are being affected by the ViewPager
. Is there a parent layout where the ViewPager
resides? Check if you have a parent view. The dummy animation can be causing the parent layout to re-draw itself and the child elements many-a-times. This is especially troublesome when you have...wait for it...Nested views!