Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CustomNavDrawer1.3
<!--
Basically, we have to add whole of our content view along with the toolbars inside a temporary _holder_ .
And as our drawer slides,
we will be scaling down the height of this holder in a relative factor, by overriding 'on drawer slide(){…}'
-->
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
...>
<LinearLayout <--------holder layout
android:id="@+id/holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<...>
</...>
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
...
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
final LinearLayout holder=findViewById(R.id.holder);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
{
@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
//this code-block is the real player behind this beautiful ui
// basically, it's a mathemetical calculation which handles the shrinking of
// our content view.
float scaleFactor = 7f;
float slideX = drawerView.getWidth() * slideOffset;
holder.setTranslationX(slideX);
holder.setScaleX(1 - (slideOffset / scaleFactor));
holder.setScaleY(1 - (slideOffset / scaleFactor));
super.onDrawerSlide(drawerView, slideOffset);
}
};
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.