youth5201314 / banner

🔥🔥🔥Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
Apache License 2.0
12.92k stars 2.51k forks source link

第二张没有预加载出来,需要手动滑出来才行 #1202

Closed haoYeaph closed 10 months ago

haoYeaph commented 1 year ago

0869a699e6a6dafe0c4f31ada1e0cbb

9c6579f72d14b3163ba8d6216d3ea87 ` 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);
    }
}

} `