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 change the scale of the on focus image. #4

Closed
Giosk opened this issue May 10, 2016 · 8 comments
Closed

How to change the scale of the on focus image. #4

Giosk opened this issue May 10, 2016 · 8 comments

Comments

@Giosk
Copy link

Giosk commented May 10, 2016

Is it possible to change the size of the on focus image?
The difference is huge between the image and their left and right children.
By the way you did a great work!

Thanks
Giosk

@mig35
Copy link
Member

mig35 commented May 10, 2016

Hi Giosk!
What do you mean by focus image and what size change do you want?
In sample zoom effect is done by this line:
layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());

@Giosk
Copy link
Author

Giosk commented May 10, 2016

Hi mig35,
I mean that the size of the current item (first image) has a size that is much bigger than his children, so the space indicated with the red arrow is bigger than the space indicated by the blue arrow. Is it possible to customize your library for creating the same thing, but with more proportionated spaces?

Thanks for your help 👍

example

@mig35
Copy link
Member

mig35 commented May 11, 2016

Hi Giosk,
as I said it is done by math algorithm that is written in this class CarouselZoomPostLayoutListener. So you can remove this line:
layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());
and create your own PostLayoutListener with different zoom effect.
Now zoom calculated by this line:
(4 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1) / 2);
and translate by this:
child.getWidth() * (1 - scale) / 2f

You will use this value: itemPositionToCenterDiff. This value is int when there is no scroll and current item is in some fixed position from center. Center item is 0, right items are > 0, left are < 0. So if there is no scroll then "child 1 left" will be -1, "first image" will be 0, "child 1 right" will be 1. As soon as user start scrolling, itemPositionToCenterDiff will be a float, that indicates position of item center to full receclerview center. so if first image will be in the right of the center, it's value will be from 0 to 1 (for example 0.34f). And so on. You should write scale and transition logic for your needs.
If you like, you can make it reusable and we will glad to include it to our library.

If you have any question, ask me :)

@Giosk
Copy link
Author

Giosk commented May 11, 2016

Hi mig35,
thanks for your explanation, I'll try to customize the scaling function.
See you soon.

Thanks again
Giosk

@mig35 mig35 closed this as completed May 20, 2016
@brucetoo
Copy link

Hi mig35,
Could you please explan why you choose this math algorithm,
(4 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1) / 2);
Is there has any hint ? although i know what's this meanings.
Thanks
Bruce

@mig35
Copy link
Member

mig35 commented Jun 15, 2016

Hi brucetoo,

Math.abs(itemPositionToCenterDiff) changes from 0 to (mMaxVisibleItems+1).

If itemPositionToCenterDiff=0, we need function to be 1 (we don't scale view in upper way).
If itemPositionToCenterDiff>0, then we need function to be from 1 to 0. And we would like this function to tend to zero. This way atan/Pi is a good way around.

We could use any other function to get this result, but I choose this one.

@brucetoo
Copy link

Thanks for your explain,mig35.

@mig35
Copy link
Member

mig35 commented Jun 15, 2016

You are welcome, brucetoo

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