Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to implement stack transformation in opposite direction ,please help #18

Open
Rishabh-sx opened this issue Nov 16, 2017 · 2 comments

Comments

@Rishabh-sx
Copy link

Rishabh-sx commented Nov 16, 2017

I want to implement stack transformation in opposite direction ,please help

@Rishabh-sx Rishabh-sx changed the title I implement stack transformation in opposite direction ,please help I want to implement stack transformation in opposite direction ,please help Nov 16, 2017
@Rishabh-sx
Copy link
Author

Rishabh-sx commented Nov 17, 2017

Hi I found the solution for the same.
By overriding the method below we can achieve this.

public void transformPage(View view, float position) {
if (position < -1) {
view.setAlpha(0);
} else if (position <= 0) {
view.setAlpha(1 + position);
view.setTranslationX(view.getWidth() * -position);
view.setTranslationZ(-1);
view.setScaleX(1);
view.setScaleY(1);
} else if (position <= 1) {
view.setAlpha(1);
view.setScaleX(1);
view.setScaleY(1);
view.setTranslationZ(1);
} else {
view.setAlpha(1);
}
}

@filanjuraj
Copy link

filanjuraj commented May 21, 2018

Hey I found the solution, you just have to find out from which side are you dragging and then pass it.

       ((ViewPager) fragmentViews).setPageTransformer(true, new DefaultTransformer(){

        @Override
        protected void onTransform(View view, float position) {
            int a = Float.compare(position, 0.000000000f);
            view.setTranslationX(a >= 0 ? 0f : -view.getWidth() * position);
            view.setTranslationZ(a >= 0 ? 1 : -1);
        }

        @Override
        protected void onPreTransform(View view, float position) {
            final float width = view.getWidth();

            int a = Float.compare(position, 0.000000000f);

            view.setRotationX(0);
            view.setRotationY(0);
            view.setRotation(0);
            view.setScaleX(1);
            view.setScaleY(1);
            view.setPivotX(0);
            view.setPivotY(0);
            view.setTranslationY(0);

            if (!((CustomViewPager)fragmentViews).isFromLeftSwipe()) {
                view.setTranslationX(a >= 0 ? width * position : 0f);
            } else {
                view.setTranslationX(a >= 0 ? 0f : -width * position);
            }


            if (hideOffscreenPages()) {
                view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
            } else {
                view.setAlpha(1f);
            }

        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants