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

Spacing between 1st right & 1st left item in Carousel #34

Open
saisasanksunkavalli opened this issue Jan 4, 2017 · 15 comments
Open

Spacing between 1st right & 1st left item in Carousel #34

saisasanksunkavalli opened this issue Jan 4, 2017 · 15 comments

Comments

@saisasanksunkavalli
Copy link

saisasanksunkavalli commented Jan 4, 2017

Im using layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());

But it is giving me a spacing like this between the center item & 1st right, 1st left like this
image

How to reduce the gap ?

Regards,
Sasank

@mig35
Copy link
Member

mig35 commented Jan 10, 2017

Hi @saisasanksunkavalli.
This gap is done by CarouselZoomPostLayoutListener. You can check its algorithm.
Zoom is controlled by "scale" parameter.
Spacing is controlled by translate parameters.

I suggest you to write custom ZoomPostLayoutListener. And change scale parameter not so fast. This will resolve your issue.

@Kisty
Copy link

Kisty commented Jan 12, 2017

A nice API wouldn't go amiss though. Perhaps a setter which takes a value and applies that to the scale given?

@mig35
Copy link
Member

mig35 commented Jan 20, 2017

Yep, @Kisty. I was thinking about it, but haven't started this yet :)

@Kisty
Copy link

Kisty commented Jan 27, 2017

Perhaps it might be worth offering a few effects, such as on using a slow drop off, like

f(x) = x^2

And perhaps using cos(x) for medium dropoff.

@RomiValladares
Copy link

Hi! I'm having the same problem.
In my implementation of the PostLayoutListener, I'm returning values like:

itemPositionToCenterDiff=3.0 scale=0.7
itemPositionToCenterDiff=2.0 scale=0.8
itemPositionToCenterDiff=1.0 scale=0.9
itemPositionToCenterDiff=0.0 scale=1.0

I thought this would make the difference between views the same, but I'm getting the same result as OP (with a vertical orientation).

    @Override
    public ItemTransformation transformChild(@NonNull final View child, final float itemPositionToCenterDiff, final int orientation) {
        //final float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 0.5) / Math.PI + 1));
        float auxPos = Math.abs(itemPositionToCenterDiff);
        final float scale = auxPos > 0 ? 1 - (auxPos / 10) : 1;

//other stuff

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

Am I missing something?

@avalenzuelac
Copy link

same problem :(

@NirmalyaSin
Copy link

Can someone tell how to increase the height of the views which are immediate left and right of the center element ?

@NirmalyaSin
Copy link

Yes I am doing so but the gap between the views are changing, height of the immediate left and right views are not getting changed. Can you please tell which variables can be altered to get the result ?

@mig35
Copy link
Member

mig35 commented Apr 21, 2020

As I remember you should change scale @NirmalyaSin

@NirmalyaSin
Copy link

final float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1));

@mig35 can you explain how you are setting the scale here ?

@mig35
Copy link
Member

mig35 commented Apr 21, 2020

this is a kind of magic to convert item position (from 0 to maxVisibleItems) to scale factor that is needed to be for this item.

you can play around with this function @NirmalyaSin

@NirmalyaSin
Copy link

NirmalyaSin commented Apr 21, 2020

@mig35 Yes but I need to change the height of the visible items apart from the center one. But the height is not getting changed. Can you tell me how to increase or decrease the height ?

@mig35
Copy link
Member

mig35 commented Apr 21, 2020

@NirmalyaSin
as I can see if you pass scaleY then the view will be scaled and its visible height will be changed.
The code can be found here: https://github.com/Azoft/CarouselLayoutManager/blob/master/CarouselLayoutManager/carousel/src/main/java/com/azoft/carousellayoutmanager/CarouselLayoutManager.java#L469

You can debug the library and if you find any issue you are welcome to write a PR.

@NirmalyaSin
Copy link

Thanks a lot @mig35 I was able to attain the desired view.

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

No branches or pull requests

6 participants