在我的应用程序中,我使用了 Navigation Drawer,它工作得很好。但是如果要显示的 fragment 包含很多 TextView、ImageView 和布局,当我单击该项目时, View 会出现故障。我会改善这种滞后。我的 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();
所以我想我会在菜单关闭后立即替换 fragment ......有什么想法吗?
最佳答案
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) 中执行 fragment 操作。
关于android - 抽屉导航很慢, View 复杂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20164633/