导航抽屉与复杂视图慢视图、抽屉、复杂

2023-09-06 02:37:49 作者:无言温柔

在我的应用程序我使用的抽屉式导航,它工作得很好。但是,如果该片段显示含有较多的TextView,ImageView的布局,当我点击该项目,该视图毛刺。我想改善这种滞后。效果是一样的我的Galaxy Nexus的和的Nexus 4,所以我认为这个问题是,我有2个命令对应的在同一时间。

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?

推荐答案

随着documentation说:

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回调(的例如这里)。