4

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.

blork
  • 2,150
  • 6
  • 26
  • 45
  • Set the offscreen page limit of your viewPager to zero or one (setOffscreenPageLimit(0)). – Luca Ziegler Feb 02 '16 at 11:09
  • I'm already setting it to 1; setting it to 0 gives the log message `Requested offscreen page limit 0 too small; defaulting to 1`. – blork Feb 02 '16 at 11:13

1 Answers1

1

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!

Subby
  • 5,370
  • 15
  • 70
  • 125