Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

java - ViewPager page scaling issue with page transformer

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 possible 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 expected output

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);
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...