package cn.bingoogolapple.bgabanner.transformer; import android.support.v4.view.ViewCompat; import android.view.View; /** * 作者:王浩 邮件:bingoogolapple@gmail.com * 创建时间:15/6/19 上午8:41 * 描述: */ public class ZoomPageTransformer extends BGAPageTransformer { private float mMinScale = 0.85f; private float mMinAlpha = 0.65f; public ZoomPageTransformer() { } public ZoomPageTransformer(float minAlpha, float minScale) { setMinAlpha(minAlpha); setMinScale(minScale); } @Override public void handleInvisiblePage(View view, float position) { ViewCompat.setAlpha(view, 0); } @Override public void handleLeftPage(View view, float position) { float scale = Math.max(mMinScale, 1 + position); float vertMargin = view.getHeight() * (1 - scale) / 2; float horzMargin = view.getWidth() * (1 - scale) / 2; ViewCompat.setTranslationX(view, horzMargin - vertMargin / 2); ViewCompat.setScaleX(view, scale); ViewCompat.setScaleY(view, scale); ViewCompat.setAlpha(view, mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha)); } @Override public void handleRightPage(View view, float position) { float scale = Math.max(mMinScale, 1 - position); float vertMargin = view.getHeight() * (1 - scale) / 2; float horzMargin = view.getWidth() * (1 - scale) / 2; ViewCompat.setTranslationX(view, -horzMargin + vertMargin / 2); ViewCompat.setScaleX(view, scale); ViewCompat.setScaleY(view, scale); ViewCompat.setAlpha(view, mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha)); } public void setMinAlpha(float minAlpha) { if (minAlpha >= 0.6f && minAlpha <= 1.0f) { mMinAlpha = minAlpha; } } public void setMinScale(float minScale) { if (minScale >= 0.6f && minScale <= 1.0f) { mMinScale = minScale; } } }