Git Product home page Git Product logo

Comments (5)

onka13 avatar onka13 commented on August 10, 2024

check the below code and change scale and translate parameters. Or you can change in layout with margin or padding.

        layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener() {
            @Override
            public ItemTransformation transformChild(@NonNull View child, float itemPositionToCenterDiff, int orientation) {
                float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1));
                float translateY;
                float translateX;
                if (CarouselLayoutManager.VERTICAL == orientation) {
                    final float translateYGeneral = child.getMeasuredHeight() * (1 - scale) * 2 * 1.15f;
                    translateY = Math.signum(itemPositionToCenterDiff) * translateYGeneral;
                    translateX = 0;
                } else {
                    final float translateXGeneral = child.getMeasuredWidth() * (1 - scale) * 2 * 1.15f;
                    translateX = Math.signum(itemPositionToCenterDiff) * translateXGeneral;
                    translateY = 0;
                }
                //CommonHelper.log("itemPositionToCenterDiff: " + itemPositionToCenterDiff + ", scale: " + scale + ", x: " + translateX + ",y: " + translateY);
                scale = 1;
                if (-0.5 < itemPositionToCenterDiff && itemPositionToCenterDiff < 0.5) {
                    child.setAlpha(1f);
                } else {
                    child.setAlpha(0.5f);
                }
                return new ItemTransformation(scale, scale, translateX, translateY);
            }
        });

from carousellayoutmanager.

erylljoy24 avatar erylljoy24 commented on August 10, 2024

thank you for this block of code @onka13 and now my problem is when ever i scroll the items the image at the center is a bit jumpy/jerky.

from carousellayoutmanager.

onka13 avatar onka13 commented on August 10, 2024

@erylljoy24 could you please share your code. (PostLayoutListener)

from carousellayoutmanager.

erylljoy24 avatar erylljoy24 commented on August 10, 2024

@onka13 i used this block of code

`public ItemTransformation transformChild(@nonnull View child, float itemPositionToCenterDiff, int orientation) {
final float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.20) / Math.PI + 1));

    final float translateY;
    final float translateX;
    if (CarouselLayoutManager.VERTICAL == orientation) {
        final float translateYGeneral = child.getMeasuredHeight() * (1 - scale) * 2 * .50f;
        translateY = Math.signum(itemPositionToCenterDiff) * translateYGeneral;
        translateX = 0;
    } else {// 0.60

        final float translateXGeneral = (float) ((0 - scale) * .20 * .50f);
        translateX = Math.signum(itemPositionToCenterDiff) * translateXGeneral;
        translateY = 0;
    }

    return new ItemTransformation(scale, scale, translateX, translateY);
    
}`

i don't know why it caused a jumpy scroll

from carousellayoutmanager.

sagarhudge avatar sagarhudge commented on August 10, 2024

@erylljoy24 same issue i'm facing please help if you have solution

from carousellayoutmanager.

Related Issues (20)

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.