ViewPager page scaling issue with page transformer

2019-01-28 08:45发布

问题:

Hi i'm developing an app where i'm using viewpager to make custom animation with viewpager transformer but the problem is that there is scaling issue with viewpager page transformer.I tried every posssible x and y scaling but still the problem is the same. I'm having hard time understanding the problem please if someone can help me out here. below is the image of what i'm trying to achieve

Update: Well looks i did not find the solution yet but still trying to figure as i'm almost there with just left with the designing of cardstack look. My page Transformation code

public class CardStackTransformer implements ViewPager.PageTransformer {
    private static final float DEFAULT_CURRENT_PAGE_SCALE = 1.0f;
    private static final float OTHER_PAGE_SCALE = 0.9f;
    private int dimen;

    @Override
    public void transformPage(@NonNull View view, float position) {

        //view.setScaleX(DEFAULT_CURRENT_PAGE_SCALE);
        // view.setScaleY(DEFAULT_CURRENT_PAGE_SCALE);
        /*dimen = view.getWidth();
        int pageWidth = view.getWidth();
        final float translateValue = position * -pageWidth;
        if (translateValue < -pageWidth) {
            view.setTranslationX(translateValue);
        }

        if (position < -1) {
            view.setAlpha(0);

        } else if (position <= 0) {
            view.setAlpha(1.0f);
            view.setTranslationX(view.getWidth() * -position);
            view.setTranslationY(0);
            view.setScaleX(1);
            view.setScaleY(1);
        } else if (position <= 1) {
            view.setTranslationX(dimen * position);
            view.setAlpha(-0.5f * position + 1.0f);
            //  view.setTranslationX((-dimen / 1.1F) * position);
            view.setTranslationX(view.getWidth() * -position);
            view.setTranslationY((dimen / 200.09f) * position);

            float scaleFactor = OTHER_PAGE_SCALE
                    + (1 - OTHER_PAGE_SCALE) * (1 - Math.abs(position));
            view.setScaleX(scaleFactor);
            view.setScaleY(scaleFactor);
            //view.setScaleX(OTHER_PAGE_SCALE);
            //view.setScaleY(OTHER_PAGE_SCALE);
        } else {
            view.setAlpha(0);
        }*/
        view.setScaleX(DEFAULT_CURRENT_PAGE_SCALE);
        view.setScaleY(DEFAULT_CURRENT_PAGE_SCALE);
        dimen = view.getWidth();

        if(position < -1) {
            view.setAlpha(0);

        } else if(position <= 0) {
            view.setAlpha(1.0f);
            view.setTranslationX(0);
            view.setTranslationY(0);
            view.setScaleX(DEFAULT_CURRENT_PAGE_SCALE);
            view.setScaleY(OTHER_PAGE_SCALE);
        } else if(position <= 1) {
            final float scaleFactor = OTHER_PAGE_SCALE + (1 - OTHER_PAGE_SCALE) * (1 - Math.abs(position));

           // view.setTranslationX(dimen * -position);
            view.setAlpha(-0.5f * position + 1.0f);
            view.setTranslationX((-dimen / 1.1F) * position);
            view.setTranslationY((dimen / 209.9f)*position);
            view.setTranslationX(view.getWidth() * -position);
            view.setScaleX(scaleFactor);
            view.setScaleY(scaleFactor);
        } else {
            view.setAlpha(0);
        }
    }
}