如何使导航抽屉运动平稳?

时间:2018-08-08 11:14:01

标签: android navigationbar

我想问您一些有关导航栏的问题。我已经成功做到了。但是我要如何使其平稳运行。这意味着,例如,当用户单击“关于我们”时,它将转到“关于我们”界面,而无需向左滑动导航。如视频中所示,我向左滑动导航,以便可以看到“关于我们”界面。

        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

1 个答案:

答案 0 :(得分:0)

通常,导航抽屉很光滑,但是如果打开不顺畅,则必须有一些大尺寸的图像。

检查图像的大小(如果正在使用)并调整其大小

或者如果不是那样,则在Navigation Drawer tutorial的帮助下创建导航抽屉。

借助于此,您将能够为您的应用创建标准的导航抽屉。