Android,滑动抽屉
我注意到 animateOpen()
、animateClose()
和 animateToggle()
正在执行相同的功能,这意味着它们中的任何一个都可以替换其他人。
我注意到的唯一区别是动画的速度因一种方法而异,如下所示:
animateOpen()
,打开时的动画更快比关闭时的动画。animateClose()
,关闭时的动画比打开时的动画更快。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:
animateOpen()
, the animation while opening is faster than the animation while closing.animateClose()
, the animation while closing is faster than the animation while opening.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已确认,在两个不同的设备上。
animateClose()
有时会以动画方式将抽屉打开。立即函数(
close
和open
)似乎按您的预期工作。鉴于此,我建议对 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
andopen
) 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
OnDrawerXxxListener
s 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()
andisClosing()
based on your subclass's state plus the existingisMoving()
method.animateOpen
、animateclose
和animateToggle
公共方法将分别使幻灯片打开、关闭或用动画切换。这些方法必须与 open、close 进行比较,后者将在没有动画的情况下打开和关闭滑块。默认实现中动画的速度不应改变。animateOpen
,animateclose
andanimateToggle
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.