问题
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?
回答1:
As the 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.
What you could do, is have an event listener for your drawer, and do the fragment operation in the onDrawerClosed callback (example here).
回答2:
I have found that if you load the views in the fragment in the onCreateView()
method it will slow down the fragment loading. Try loading the fragment related views in the onStart()
method.
来源:https://stackoverflow.com/questions/20164633/navigation-drawer-is-slow-with-complex-view