DrawerLayout 的项目点击 - 什么时候更换片段合适? [英] DrawerLayout's item click - When is the right time to replace fragment?

查看:38
本文介绍了DrawerLayout 的项目点击 - 什么时候更换片段合适?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用导航抽屉模式(使用 DrawerLayout)的应用程序.

I'm developing an application which uses the navigation drawer pattern (With DrawerLayout).

每次单击抽屉的项目,都会替换主容器中的片段.

Each click on a drawer's item, replaces the fragment in the main container.

但是,我不确定什么时候是进行片段交易的合适时机?抽屉什么时候开始关闭?还是关门后?

However, I'm not sure when is the right time to do the fragment transaction? When the drawer starts closing? Or after it is closed?

在谷歌的文档示例中,你可以看到他们正在做交易单击项目后立即关闭抽屉.
结果,抽屉看起来很卡顿,不光滑,而且看起来很糟糕(我的应用程序也发生过这种情况).

In google's documentaion example, you can see that they are doing the transaction right after the item click, and then close the drawer.
As a result, the drawer seems laggy and not smooth, and it looks very bad (It happens in my application too).

Gmail

In Gmail and Google Drive applications, on the other way, It seems like they are doing the transaction after the drawer closed (Am I Right?).
As a result, the drawer is not laggy and very smooth, BUT it takes about 1 second (the time it takes to the drawer get closed) at least, to see the next fragment.

好像没有办法在直接进行fragment事务的时候抽屉是平滑的.

It seems like there is no way the drawer will be smooth when immediately doing fragment transaction.

你怎么看?

提前致谢!

推荐答案

是的,不能同意更多,执行片段(带视图)事务会导致布局传递,导致正在动画的视图上出现卡顿动画,引用 DrawerLayout 文档:

Yup, couldn't agree more, performing a fragment (with view) transaction results in a layout pass which causes janky animations on views being animated, citing DrawerLayout docs:

DrawerLayout.DrawerListener 可用于监视抽屉视图的状态和运动.避免在动画期间执行昂贵的操作,例如布局,因为它会导致卡顿;尝试在 STATE_IDLE 状态期间执行昂贵的操作.

DrawerLayout.DrawerListener can be used to monitor the state and motion of drawer views. Avoid performing expensive operations such as layout during animation as it can cause stuttering; try to perform expensive operations during the STATE_IDLE state.

所以请在抽屉关闭或有人修补支持库以某种方式修复它后执行您的片段事务:)

So please perform your fragment transactions after the drawer is closed or somebody patches the support library to somehow fix that :)

这篇关于DrawerLayout 的项目点击 - 什么时候更换片段合适?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆