Closed haoYeaph closed 10 months ago
` public class CardTypeTransformer implements ViewPager2.PageTransformer { private static final int mOffset = 22; private Context context;
public CardTypeTransformer(Context context) { this.context = context; } @Override public void transformPage(View page, float position) { if (position <= 0.0f) {//被滑动的那页 page.setTranslationX(0f); page.setTranslationZ(0.0f); page.setScaleX(1f); page.setScaleY(1f); } else {//未被滑动的页 page.setTranslationX(Utils.dip2px(context, mOffset) * position - page.getWidth() * position); //缩放比例 float scale = (page.getWidth() - Utils.dip2px(context, mOffset) * position) / (float) (page.getWidth()); page.setScaleX(scale); page.setScaleY(scale); page.setTranslationZ(-position); } //只显示三个 if (position > 2.0f) { page.setAlpha((3 - position)); } else { page.setAlpha(1); } }
} `
` public class CardTypeTransformer implements ViewPager2.PageTransformer { private static final int mOffset = 22; private Context context;
} `