Last active
December 21, 2019 05:55
-
-
Save jayrambhia/6066a732c3bf5ebde3b9a03da375cfa5 to your computer and use it in GitHub Desktop.
ViewPager Cards
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
public class CardsPagerTransformerBasic implements ViewPager.PageTransformer { | |
private int baseElevation; | |
private int raisingElevation; | |
private float smallerScale; | |
public CardsPagerTransformerBasic(int baseElevation, int raisingElevation, float smallerScale) { | |
this.baseElevation = baseElevation; | |
this.raisingElevation = raisingElevation; | |
this.smallerScale = smallerScale; | |
} | |
@Override | |
public void transformPage(View page, float position) { | |
float absPosition = Math.abs(position); | |
if (absPosition >= 1) { | |
page.setElevation(baseElevation); | |
page.setScaleY(smallerScale); | |
} else { | |
// This will be during transformation | |
page.setElevation(((1 - absPosition) * raisingElevation + baseElevation)); | |
page.setScaleY((smallerScale - 1) * absPosition + 1); | |
} | |
} | |
} |
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
public class CardsPagerTransformerShift implements ViewPager.PageTransformer { | |
private int baseElevation; | |
private int raisingElevation; | |
private float smallerScale; | |
private float startOffset; | |
public CardsPagerTransformerShift(int baseElevation, int raisingElevation, float smallerScale, float startOffset) { | |
this.baseElevation = baseElevation; | |
this.raisingElevation = raisingElevation; | |
this.smallerScale = smallerScale; | |
this.startOffset = startOffset; | |
} | |
@Override | |
public void transformPage(View page, float position) { | |
float absPosition = Math.abs(position - startOffset); | |
if (absPosition >= 1) { | |
page.setElevation(baseElevation); | |
page.setScaleY(smallerScale); | |
} else { | |
// This will be during transformation | |
page.setElevation(((1 - absPosition) * raisingElevation + baseElevation)); | |
page.setScaleY((smallerScale - 1) * absPosition + 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use this code?