Navigation Drawer is slow with complex view

ぐ巨炮叔叔 提交于 2020-01-29 07:12:44

问题


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?


回答1:


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).




回答2:


I have found that if you load the views in the fragment in the onCreateView() method it will slow down the fragment loading. Try loading the fragment related views in the onStart() method.



来源:https://stackoverflow.com/questions/20164633/navigation-drawer-is-slow-with-complex-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!