7

在我的应用程序中,我使用导航抽屉,它工作得很好。但是如果要显示的片段包含很多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(); 

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

回答

7

由于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)做的片段操作。

+0

谢谢你,一个很好的解决方案。 – mdikici

0

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