How to smooth the navigation drawer movement?
Clash Royale CLAN TAG#URR8PPP
How to smooth the navigation drawer movement?
I would like to ask you something about the navigation bar. I already successfully make it. But how I want to make it move smoothly. Which means, for example, when user click on About Us, it will go to the About Us interface without need to swipe left the navigation. As shown in the video, I slide left the navigation so that I can see the About Us interface.
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener()
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item)
switch (item.getItemId())
case R.id.nav_home:
HomeFragment homeFragment = new HomeFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,homeFragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new HomeFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Home Fragment");
item.setCheckable(true);
break;
case R.id.nav_aboutUs:
AboutusFragment aboutusFragment = new AboutusFragment ();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,aboutusFragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new AboutusFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("About Us Fragment");
item.setCheckable(true);
break;
case R.id.nav_tuitionCentre:
SearchtuitioncentreFragment searchtuitioncentreFragment = new SearchtuitioncentreFragment ();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,searchtuitioncentreFragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new SearchtuitioncentreFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Search Tuition Centre");
item.setCheckable(true);
break;
case R.id.nav_homeTuition:
Seachometuitionragment seachometuitionragment = new Seachometuitionragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,seachometuitionragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new Seachometuitionragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Search Home Tuition");
item.setCheckable(true);
break;
case R.id.nav_contact:
ContactusFragment contactusFragment = new ContactusFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,contactusFragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new ContactusFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Contact Us");
item.setCheckable(true);
break;
case R.id.nav_logout:
LogoutFragment logoutFragment = new LogoutFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
.replace(R.id.main_container,logoutFragment)
.addToBackStack(null)
.commit();
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, new LogoutFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Log Out");
item.setCheckable(true);
mAuth.signOut();
SendUserToLoginActivity();
break;
default:
break;
return true;
);
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.main_container, new HomeFragment());
fragmentTransaction.commit();
getSupportActionBar().setTitle("Home Fragment");
}
My apps which the navigation didnt move smoothly
yes, something like that. where to put the close drawer? :))
– Adda
Aug 8 at 11:36
You can put it before return true; after your switch statements
– Zony86
Aug 8 at 11:38
omg! its work! Thank you so much!
– Adda
Aug 8 at 11:39
2 Answers
2
Usually Navigation drawers are smooth but if it is not opening smoothly then there must some large size images.
check the size of images if you are using and resize them
Or if that's not the scene create the navigation drawer with help of Navigation Drawer tutorial.
With the help of this you will be able to create a standard navigation drawer for your apps.
Thank you sir! Already got it yeay!
– Adda
Aug 8 at 11:39
what's the issue ??
– Chirag Sharma
Aug 8 at 11:40
I didnt put navigationView.closeDrawer(GravityCompat.START);
– Adda
Aug 8 at 11:41
It's not about just large images. It's about your layout's complexity.
Navigation Drawer is slow with complex view
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Is your question how to close the drawer after a menu item is clicked? If so all you need is after fragment has been loaded : navigationView.closeDrawer(GravityCompat.START);
– Zony86
Aug 8 at 11:21