其他分享
首页 > 其他分享> > android – 导航抽屉速度慢,视图复杂

android – 导航抽屉速度慢,视图复杂

作者:互联网

在我的应用程序中我使用导航抽屉,它工作得很好.但是如果要显示的片段包含很多TextView,ImageView和Layout,当我单击该项时,视图就会出现故障.我会改善这种滞后.我的Galaxy Nexus和Nexus 4的效果是一样的,所以我认为问题在于我同时有2个命令.

  //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();

所以我想我会在菜单关闭后更换片段..任何想法?

解决方法:

作为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.

您可以做的是,为您的抽屉设置一个事件监听器,并在onDrawerClosed回调中执行片段操作(example here).

标签:android,performance,android-fragments,navigation-drawer,view
来源: https://codeday.me/bug/20191006/1862169.html