Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Created June 23, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virendersran01/2a519c0e2ad7409cb21100377277dda5 to your computer and use it in GitHub Desktop.
Save virendersran01/2a519c0e2ad7409cb21100377277dda5 to your computer and use it in GitHub Desktop.
Animated Navigation Drawer with OnSlide
private void animateNavigationDrawer() {
//Add any color or remove it to use the default one!
//To make it transparent use Color.Transparent in side setScrimColor();
//drawerLayout.setScrimColor(Color.TRANSPARENT);
drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Scale the View based on current slide offset
final float diffScaledOffset = slideOffset * (1 - END_SCALE);
final float offsetScale = 1 - diffScaledOffset;
contentView.setScaleX(offsetScale);
contentView.setScaleY(offsetScale);
// Translate the View, accounting for the scaled width
final float xOffset = drawerView.getWidth() * slideOffset;
final float xOffsetDiff = contentView.getWidth() * diffScaledOffset / 2;
final float xTranslation = xOffset - xOffsetDiff;
contentView.setTranslationX(xTranslation);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment