Created
November 15, 2015 19:28
-
-
Save bholota/2e14f5ce43a343422c22 to your computer and use it in GitHub Desktop.
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 static class FadeoutBehavior extends CoordinatorLayout.Behavior<View> { | |
private int startPos = 0; | |
private int finalPos = 0; | |
@Override | |
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { | |
return dependency instanceof AppBarLayout; | |
} | |
@Override | |
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { | |
shouldInitProperties(child, dependency); | |
float fullDistance = startPos - finalPos; | |
float currDistance = child.getY() + child.getHeight() / 2f - finalPos; | |
float x = currDistance * 100 / fullDistance; | |
child.setAlpha(x / 100f); | |
return true; | |
} | |
private void shouldInitProperties(View child, View dependency) { | |
if(startPos == 0) { | |
startPos = (int) child.getY() + child.getHeight() / 2; | |
} | |
if(finalPos == 0 ){ | |
finalPos = dependency.getHeight() / 2; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment