我正在尝试为VIEwPager中的项目制作动画,而Pagetransformer符合要求.我希望它向后兼容Android 2.2所以我使用的是支持v4库.然而…
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.
因此Pagetransformer不适用于旧版本
我正在使用Jake Wharton’s NineOldAndroids库,所以我可以使用该API,但我不确定如何为VIEwPager做动画.
我怎么能这样做?
解决方法:
您需要使用AnimatorProxy包装器实现Pagetransformer,以在视图上设置转换属性.
然后,最困难的部分是VIEwPager将忽略较低API版本中的Pagetransformer.因此,您需要修改VIEwPager本身以使用Pagetransformer.
我有一个forked version of the support library on GitHub允许这个以及使用NineoldAndroIDs动画师进行自定义片段转换.使用animator-Transition分支.它是一个maven项目,因此您可以从v4子目录构建它.
public class ZoomOutPagetransformer implements Pagetransformer { private static float MIN_SCALE = 0.85f; private static float MIN_Alpha = 0.5f; public voID transformPage(VIEw vIEw, float position) { int pageWIDth = vIEw.getWIDth(); int pageHeight = vIEw.getHeight(); AnimatorProxy proxy = AnimatorProxy.wrap(vIEw); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. proxy.setAlpha(0); } else if (position <= 1) { // [-1,1] // Modify the default slIDe Transition to shrink the page as well float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); float vertmargin = pageHeight * (1 - scaleFactor) / 2; float horzmargin = pageWIDth * (1 - scaleFactor) / 2; if (position < 0) { proxy.setTranslationX(horzmargin - vertmargin / 2); } else { proxy.setTranslationX(-horzmargin + vertmargin / 2); } // Scale the page down (between MIN_SCALE and 1) proxy.setScaleX(scaleFactor); proxy.setScaleY(scaleFactor); // Fade the page relative to its size. proxy.setAlpha(MIN_Alpha + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_Alpha)); } else { // (1,+Infinity] // This page is way off-screen to the right. proxy.setAlpha(0); } }}
总结 以上是内存溢出为你收集整理的android – 向后兼容的PageTransformer全部内容,希望文章能够帮你解决android – 向后兼容的PageTransformer所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)