Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Drawer is slow with complex view

In my app i'm using Navigation Drawer and it works very fine. But if the Fragment to show contains much TextView, ImageView and Layout, when i click the item, the view is glitching. I would improve this lag. The effect is the same by my Galaxy Nexus and with Nexus 4 so i think the problem is that i have 2 comands in the same time.

  //On item click - First comand (Close Drawer) 
  mDrawerList.setItemChecked(position, true);
  setTitle(mStringTitles[position]);
  mDrawerLayout.closeDrawer(mDrawerView);

    // Second comand (Replace Fragment)        
    getFragmentManager()
   .beginTransaction()
   .replace(R.id.firts_view, new FragmentNew())
   .commit();

So I thought I'd replace the fragment just after the menu is closed .. any ideas?

like image 420
Fabrizio Billeci Avatar asked Nov 23 '13 16:11

Fabrizio Billeci


1 Answers

As the documentation says:

Avoid performing expensive operations such as layout during animation as it can cause stuttering;
try to perform expensive operations during the STATE_IDLE state.

What you could do, is have an event listener for your drawer, and do the fragment operation in the onDrawerClosed callback (example here).

like image 86
mbmc Avatar answered Nov 16 '22 05:11

mbmc