Created
August 19, 2020 20:04
AnimatedLayout part 5: update LinearLayout with parallaxValue
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
@Override | |
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, | |
RecyclerView.State state) { | |
... | |
if (parentLayout != null) { | |
animatedLayout = parentLayout.findViewById(R.id.transformItem); | |
float translateValue = computeCurrentParallaxOffset(parentLayout); | |
animatedLayout.applyParallax(translateValue); | |
} | |
... | |
} | |
private float computeCurrentParallaxOffset(View animatedItem) { | |
float parallaxOffsetMax = animatedItem.getHeight() / 8f; | |
float centerRecyclerViewY = computeRecyclerViewCenterY(); | |
float fulOffsetFromCenterPx = animatedItem.getHeight() / 2f + centerRecyclerViewY; | |
float centerItemY = computeItemCenterY(animatedItem); | |
float currentOffsetFromCenterPx = centerRecyclerViewY - centerItemY; | |
float normalizedCurrentScrollOffset = currentOffsetFromCenterPx / fulOffsetFromCenterPx; | |
float translateFromCenterY = normalizedCurrentScrollOffset * parallaxOffsetMax; | |
return translateFromCenterY; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment