问题
I am trying to design a complicated parallaxing animation that resides inside a ViewPager. The animation uses onPageScrolled function's offsetPixel to calculate the position of the images. However this approach is causing a lot of problems due to the offsetPixel if scrolled fast can skip (ex: 1 to 123 to 250 to 251) and when slow it's too sensitive so the animation seems jittery.
Is there a better way to calculate the position of the screen besides offsetPixels. If so, can anyone please help me figure it out. Would appreciate it very much!
Thank you.
回答1:
Well, I don't know exactly if one of the pages has to have the parallax effect, or it has to been a parallax effect between de transition of changing pages.
I developed a small library to make the second one, https://github.com/xgc1986/ParallaxPagerLibrary
Demo: parallax demo
This library work with Views, the you can use it with imageViews to have the effect.
To do that I don't use de onPageScrolled function, basically then you don't permit to the developer to use this listener anymore, the to solve that I implemented a child of PageTransformer
来源:https://stackoverflow.com/questions/18831676/android-parallax-offsetpixel