DrawerLayout的项目点击 - 什么时候是合适的时间,以取代片段?什么时候、片段、合适、时间

2023-09-05 05:29:00 作者:倾城

我开发它采用了抽屉式导航模式(带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和Google硬盘应用,在其他的方式,好像他们正在做的交易后抽屉关闭(是吗?)。 其结果是,抽屉不是延迟非常明显,很流畅,但它需要大约1秒钟(需要到抽屉的时候关闭掉)至少到下个片段。

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.

好像是没有办法的抽屉将是顺利的时候,立即做片段的交易。

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

你怎么想的?

在此先感谢!

推荐答案

是啊,不能同意,表演的片段(与视图)交易导致的布局传递导致的看法janky动画进行动画处理,理由是 DrawerLayout docs:

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 :)