GithubHelp home page GithubHelp logo

Comments (2)

Rishabh-sx avatar Rishabh-sx commented on June 10, 2024

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

from android-viewpager-transformers.

filanjuraj avatar filanjuraj commented on June 10, 2024

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

        }
    });

from android-viewpager-transformers.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.