Created
January 4, 2020 07:41
-
-
Save Spikeysanju/91e566f9078325ecf1b57e66c98b7847 to your computer and use it in GitHub Desktop.
Center Zoom Layout for Animation RecyclerView items Like (Centre Zoom)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CenterZoomLayoutManager extends LinearLayoutManager { | |
private final float mShrinkAmount = 0.15f; | |
private final float mShrinkDistance = 0.9f; | |
public CenterZoomLayoutManager(Context context) { | |
super(context); | |
} | |
public CenterZoomLayoutManager(Context context, int orientation, boolean reverseLayout) { | |
super(context, orientation, reverseLayout); | |
} | |
@Override | |
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) { | |
int orientation = getOrientation(); | |
if (orientation == VERTICAL) { | |
int scrolled = super.scrollVerticallyBy(dy, recycler, state); | |
float midpoint = getHeight() / 2.f; | |
float d0 = 0.f; | |
float d1 = mShrinkDistance * midpoint; | |
float s0 = 1.f; | |
float s1 = 1.f - mShrinkAmount; | |
for (int i = 0; i < getChildCount(); i++) { | |
View child = getChildAt(i); | |
float childMidpoint = | |
(getDecoratedBottom(child) + getDecoratedTop(child)) / 2.f; | |
float d = Math.min(d1, Math.abs(midpoint - childMidpoint)); | |
float scale = s0 + (s1 - s0) * (d - d0) / (d1 - d0); | |
child.setScaleX(scale); | |
child.setScaleY(scale); | |
} | |
return scrolled; | |
} else { | |
return 0; | |
} | |
} | |
@Override | |
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) { | |
int orientation = getOrientation(); | |
if (orientation == HORIZONTAL) { | |
int scrolled = super.scrollHorizontallyBy(dx, recycler, state); | |
float midpoint = getWidth() / 2.f; | |
float d0 = 0.f; | |
float d1 = mShrinkDistance * midpoint; | |
float s0 = 1.f; | |
float s1 = 1.f - mShrinkAmount; | |
for (int i = 0; i < getChildCount(); i++) { | |
View child = getChildAt(i); | |
float childMidpoint = | |
(getDecoratedRight(child) + getDecoratedLeft(child)) / 2.f; | |
float d = Math.min(d1, Math.abs(midpoint - childMidpoint)); | |
float scale = s0 + (s1 - s0) * (d - d0) / (d1 - d0); | |
child.setScaleX(scale); | |
child.setScaleY(scale); | |
} | |
return scrolled; | |
} else { | |
return 0; | |
} | |
} | |
} |
Thanks for your kind words ❤️... I'm glad you liked it 😄🙌
…On Wed, 20 Jan, 2021, 8:49 pm Fathi Mohamed, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
this is beautiful!. I was looking for zoom in on click effect and tried
this one any way and I love it. thank you
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/91e566f9078325ecf1b57e66c98b7847#gistcomment-3600766>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFSQ4VS2GALVDSMAR3PRWATS23X7BANCNFSM4WK2T32Q>
.
thanks for this code, is there any possibility to change the highlighted item's colour?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is beautiful!. I was looking for zoom in on click effect and tried this one any way and I love it. thank you