Created
June 5, 2018 09:27
-
-
Save amalhanaja/c918bd4c9ab0eebb86d131be54b2e014 to your computer and use it in GitHub Desktop.
Parralax Page Transformer
This file contains 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
class ParallaxPagerTransformer : ViewPager.PageTransformer { | |
override fun transformPage(page: View, position: Float) { | |
val pageWidth = page.width | |
val pageWidthTimesPosition = pageWidth.times(position) | |
val imageScreen = page.findViewById<ImageView>(R.id.img_screen) | |
val imageBgTop = page.findViewById<ImageView>(R.id.img_bg_top) | |
val staticPosition = position <= -1.0f || position >= 1.0f | |
val zeroPosition = position == 0.0f | |
if (!staticPosition && !zeroPosition) { | |
imageScreen?.let { | |
it.translationX = pageWidthTimesPosition.times(0.5f) | |
} | |
imageBgTop?.let { | |
it.translationX = pageWidthTimesPosition.times(0.3f) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment