how to create smooth navigation drawer

前端 未结 5 490
醉话见心
醉话见心 2021-01-30 09:45

I am using this example for navigation drawer. When clicking on of item of left drawer listview it shows some images but drawerLayout closes not smoothly.

What should I

5条回答
  •  面向向阳花
    2021-01-30 10:03

    Just posting the drawerLayout.closeDrawer() on the message queue using the handler, with a minimal delay solved my problem. Handler.postDelayed() is the key here.

     public void selectItem(int position)
        {
            switch (position)
            {
                case 0:
    
                    DashboardFragment dashboardFragment = new DashboardFragment();
                    Bundle args = new Bundle();
                    args.putInt(dashboardFragment.ARG_SCREEN_NUMBER, position);
                    dashboardFragment.setArguments(args);
    
                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    
                    // Replace whatever is in the fragment_container view with this fragment,
                    // and add the transaction to the back stack so the user can navigate back
                    transaction.replace(R.id.fragmentLayout, dashboardFragment, TAG_DASHBOARD);
                    transaction.addToBackStack(null);
    
                    // Commit the transaction
                    transaction.commit();
                    getSupportFragmentManager().executePendingTransactions();
                    break;            
    
                default:
                    break;
    
            }
    
            // Highlight the selected item, update the title, and close the drawer
            drawerList.setItemChecked(position, true);
            setTitle(mScreenTitles[position]);
    
            mPendingRunnable = new Runnable()
            {
                @Override
                public void run()
                {
                    drawerLayout.closeDrawer(GravityCompat.START);
                }
            };
            mHandler.postDelayed(mPendingRunnable,50);
    
        }
    

提交回复
热议问题