I'm trying to animate items in a ViewPager and the PageTransformer fits the bill. I want it to be backwards compatible to Android 2.2 so am using the support v4 library. However...
As property animation is only supported as of Android 3.0 and forward, setting a PageTransformer on a > ViewPager on earlier platform versions will be ignored.
so PageTransformer won't work on older versions
I'm using Jake Wharton's NineOldAndroids library so I could use that API, but I'm not sure how to do animation for a ViewPager.
How could I do this?
You need to implement the
PageTransformer
using theAnimatorProxy
wrapper to set the transformation properties on the views.Then the tough part is that the
ViewPager
will ignore thePageTransformer
in lower API versions. So you need to modify theViewPager
itself to use thePageTransformer
.I have a forked version of the support library on GitHub which allows this as well as using NineOldAndroids animators for custom fragment transitions. Use the animator-transition branch. It is a maven project so you can build it from the v4 subdirectory.
As @mark.kedzierski said copied the ViewPager class from here and removed the if statement for the version (check below) and called it TransformableViewPager
I also had to change all PageTransformer to ViewPager.PageTransformer. Then did the transformations in a custom PageTranformer like this,
Ithink proxy can also be used so you don't have to write the version check.This worked even for 2.2