微信viewpaper滑动时下一页变暗的效果怎么实现??
============问题描述============
如题,在最新版的微信中,有这样的效果。
滑动页面时,下一页自动变暗。
请大神帮忙啊。
![](http://images0.cnblogs.com/blog/555444/201410/171036521388398.gif)
============解决方案1============
是不是切换时的动画啊,上个图看看
============解决方案2============
你好,这个也可以有几个实现方式,最简单的就是,设置Fragment的切换动画,代码示例:
mViewPager.setAdapter(adapter); mViewPager.setPageTransformer(true, new DepthPageTransformer());
然后看看动画实现类(这是层叠效果,其他效果你自己参照这个思路自己实现):
public class DepthPageTransformer implements ViewPager.PageTransformer { private static final float MIN_SCALE = 0.75f; public void transformPage(View view, float position) { int pageWidth = view.getWidth(); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. view.setAlpha(0); } else if (position <= 0) { // [-1,0] // Use the default slide transition when moving to the left page view.setAlpha(1); view.setTranslationX(0); view.setScaleX(1); view.setScaleY(1); } else if (position <= 1) { // (0,1] // Fade the page out. view.setAlpha(1 - position); // Counteract the default slide transition view.setTranslationX(pageWidth * -position); // Scale the page down (between MIN_SCALE and 1) float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); } else { // (1,+Infinity] // This page is way off-screen to the right. view.setAlpha(0); } } }
不懂再问我哈
============解决方案3============
切换的加入动画