如何平滑导航抽屉移动?
How to smooth the navigation drawer movement?
想请教一下关于导航栏的问题。我已经成功做到了。但是我想让它顺利移动。这意味着,例如,当用户点击关于我们时,它将转到关于我们界面,而无需向左滑动导航。如视频所示,我向左滑动导航,可以看到关于我们的界面。
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
通常导航抽屉是平滑的,但如果它打开不平滑,则必须有一些大尺寸的图像。
如果您正在使用并调整图像大小,请检查图像大小
或者,如果这不是场景,请在 Navigation Drawer tutorial 的帮助下创建导航抽屉。
借助此工具,您将能够为您的应用程序创建标准导航抽屉。
想请教一下关于导航栏的问题。我已经成功做到了。但是我想让它顺利移动。这意味着,例如,当用户点击关于我们时,它将转到关于我们界面,而无需向左滑动导航。如视频所示,我向左滑动导航,可以看到关于我们的界面。
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
通常导航抽屉是平滑的,但如果它打开不平滑,则必须有一些大尺寸的图像。
如果您正在使用并调整图像大小,请检查图像大小
或者,如果这不是场景,请在 Navigation Drawer tutorial 的帮助下创建导航抽屉。
借助此工具,您将能够为您的应用程序创建标准导航抽屉。