如何创建流畅的导航抽屉 [英] how to create smooth navigation drawer
本文介绍了如何创建流畅的导航抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将此示例用于导航抽屉.单击左侧抽屉列表视图中的项目时,它会显示一些图像,但抽屉布局无法顺利关闭.
I am using this example for navigation drawer. When clicking on of item of left drawer listview it shows some images but drawerLayout closes not smoothly.
在单击列表视图的项目后,如何平稳关闭左侧抽屉布局,我该怎么做.
What should I do here for smoothly close left drawer layout after clicking of the item of listview.
推荐答案
不确定这是最佳途径,但是我解决此问题的方法是创建一个在onDrawerClosed
中运行的未决Runnable.例如:
Not sure this is the best route, but the way I solved this was to create a pending Runnable that runs in onDrawerClosed
. Eg:
private void selectItem(final int position) {
mPendingRunnable = new Runnable() {
@Override
public void run() {
// update the main content by replacing fragments
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
}
});
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
// If mPendingRunnable is not null, then add to the message queue
if (mPendingRunnable != null) {
mHandler.post(mPendingRunnable);
mPendingRunnable = null;
}
}
这篇关于如何创建流畅的导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文