【问题标题】:Navigation Drawer is slow with complex view复杂视图的导航抽屉很慢
【发布时间】:2013-11-23 16:15:38
【问题描述】:

在我的应用程序中,我使用的是 Navigation Drawer,它运行良好。但是,如果要显示的 Fragment 包含很多 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();

所以我想我会在菜单关闭后替换片段......有什么想法吗?

【问题讨论】:

    标签: android performance view android-fragments navigation-drawer


    【解决方案1】:

    作为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) 中执行片段操作。

    【讨论】:

    • 谢谢,一个不错的解决方案。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      相关资源
      最近更新 更多