how to create smooth navigation drawer

前端 未结 5 480
醉话见心
醉话见心 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 09:56

    I don't use threads, because i need to update UI after close the navigation menu.

    Following code works for me.

    i am using fragment as member variable of class to update ui

    setFragment() function use to assign fragment to fragment variable

    In onDrawerClosed() event, i update ui.

    mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener()
    {
       @Override
       public void onItemClick(AdapterView parent, View view, int position, long id)
       {
           setFragment(position);
       }
    });
    
    
    // for getting fragment
    protected void setFragment(int p)
    {
        fragment = null;
    
        switch (position)
        {
            case 1:
                fragment = new DashboardFragment();                
                break;
        }
    
        if (fragment != null)
        {
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(p);
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    }
    
    
    // on close draw , fragment is loaded on screen
    public void onDrawerClosed(View view)
    {
       getSupportActionBar().setTitle(mTitle);
       invalidateOptionsMenu();
    
       FragmentManager fragmentManager = getSupportFragmentManager();
    
       fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
    }
    

提交回复
热议问题