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

how to set the spacing in the middle item? #42

Open
erylljoy24 opened this issue Mar 1, 2017 · 5 comments
Open

how to set the spacing in the middle item? #42

erylljoy24 opened this issue Mar 1, 2017 · 5 comments

Comments

@erylljoy24
Copy link

where do i need to set the spacing between the center item?

@onka13
Copy link

onka13 commented Mar 3, 2017

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

@erylljoy24
Copy link
Author

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.

@onka13
Copy link

onka13 commented Mar 6, 2017

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

@erylljoy24
Copy link
Author

erylljoy24 commented Mar 9, 2017

@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

@sagarhudge
Copy link

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

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

3 participants