geftimov/android-viewpager-transformers

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

Rishabh-sx opened this issue · 2 comments

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

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);
}
}

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);
            }

        }
    });