Android Parallax - offsetPixel

爷,独闯天下 提交于 2019-12-11 23:27:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!