A POC to show how to have multiple ViewPagers work in Parallax effect with each other
Code is based on this StackOverflow post: http://stackoverflow.com/q/31138652/878126
Here's how it looks like:
Currently, because there is an issue (read below), I didn't put an official release, but you can still use Gradle in case you don't care or can't reproduce the issue in your app (link here) :
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.AndroidDeveloperLB:ParallaxViewPagers:19516eb03a'
}
Just prepare the viewpagers, and for each "viewPager" that you need to allow to affect "viewPager2" , use:
viewPager.addOnPageChangeListener(new ParallaxOnPageChangeListener(viewPager,viewPager2,masterRef));
where "masterRef" is a shared AtomicReference variable that's used to decide which of them is the current "master" to affect the others.
Example of 2 ViewPagers, each can affect the other:
AtomicReference<ViewPager> masterRef=new AtomicReference<>();
viewPager.addOnPageChangeListener(new ParallaxOnPageChangeListener(viewPager,viewPager2,masterRef));
viewPager2.addOnPageChangeListener(new ParallaxOnPageChangeListener(viewPager2,viewPager,masterRef));
Sometimes, the other ViewPager might have a "flashing" effect. A workaround for this, is to pass the touch events from the container of the various viewpagers, to the master viewpager.