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



在我的应用程序中,我使用的是Navigation Drawer,它运行得很好。但是,如果要显示的片段包含许多TextView、ImageView和Layout,当我单击该项目时,视图会出现故障。我会改善这种滞后。我的Galaxy Nexus和Nexus 4的效果是一样的,所以我认为问题是我在同一时间有两个昏迷。

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

所以我想我应该在菜单关闭后立即替换碎片。。有什么想法吗?

正如文档所说:

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回调中执行片段操作(这里的示例)。

我发现,如果在onCreateView()方法中加载片段中的视图,则会减慢片段加载的速度。尝试在onStart()方法中加载与片段相关的视图。

最新更新