Android,滑动抽屉

发布于 2025-01-03 00:39:25 字数 576 浏览 3 评论 0原文

我注意到 animateOpen()animateClose()animateToggle() 正在执行相同的功能,这意味着它们中的任何一个都可以替换其他人。
我注意到的唯一区别是动画的速度因一种方法而异,如下所示:

  1. animateOpen()打开时的动画更快关闭时的动画
  2. animateClose()关闭时的动画打开时的动画更快
  3. animateToggle()两种速度相等

所以,我的问题是:
我错过了什么吗?或者我只需要在使用它们之前检查 isOpened()

我问这个问题是因为我在某处编写 animateClose() 时出现了问题,认为如果滑动抽屉已经关闭,则不会采取任何操作,但我发现它的行为完全是与 animateToggle() 相同。

I've noticed that animateOpen(), animateClose() and animateToggle() are doing the same function, meaning that any one of them can replace the others.
The only difference that I noticed was that the speed of the animation varies from one method to the other as follows:

  1. animateOpen(), the animation while opening is faster than the animation while closing.
  2. animateClose(), the animation while closing is faster than the animation while opening.
  3. animateToggle(), both speeds are equal.

So, my question is:
Am I missing something? or do I just have to check isOpened() before using any of them?

I'm asking this question because my problem raised when I wrote animateClose() somewhere, thinking that if the sliding drawer is already closed then no action will be taken, but I found out that it behaves exactly the same as animateToggle().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不回头走下去 2025-01-10 00:39:25

已确认,在两个不同的设备上。

  • 对已关闭的抽屉调用 animateClose() 有时会以动画方式将抽屉打开。
  • 在已经打开的抽屉上调用 animateOpen() 总是会(?)将抽屉设置为关闭动画。

立即函数(closeopen)似乎按您的预期工作。

鉴于此,我建议对 SlidingDrawer 进行子类化并重写打开或关闭抽屉的 5 个方法。使用一些成员变量布尔值,您应该能够确定抽屉的真实状态并调用(或不调用)适当的超类方法,从而相应地更新您的状态。

(可能还需要实现 OnDrawerXxxListener 来保持状态正确;我的抽屉只是以编程方式打开和关闭,而不是使用“句柄”,所以我没有测试它。

)添加:这样做的好处是,您可以根据子类的状态加上现有的状态添加 isOpening()isClosing() isMoving() 方法。

Confirmed, on two different devices.

  • animateClose() called on a drawer that is already closed will sometimes animate the drawer to opened.
  • animateOpen() called on a drawer that is already opened will always (?) animate the drawer to closed.

The immediate functions (close and open) seem to work as you would expect.

Given this, I would suggest subclassing the SlidingDrawer and overriding the 5 methods that open or close the drawer. Using a few member variable booleans, you should be able to determine the real state of the drawer and call (or not call) the appropriate superclass method, updating your state accordingly.

(It might also be necessary to implement the OnDrawerXxxListeners to keep your state correct; my drawer is only opened and closed programmatically, not using the "handle", so I didn't test that.)

Edit to add: The nice thing about doing this is that you can add an isOpening() and isClosing() based on your subclass's state plus the existing isMoving() method.

飘然心甜 2025-01-10 00:39:25

animateOpenanimatecloseanimateToggle 公共方法将分别使幻灯片打开、关闭或用动画切换。这些方法必须与 open、close 进行比较,后者将在没有动画的情况下打开和关闭滑块。默认实现中动画的速度不应改变。

animateOpen, animateclose and animateToggle public methods will make the slide open,close or toggle with animaiton respectively. The methods have to be compared with open, close which will open and close the slider without animation. The speed of animation should not change in default implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文