在Android中获取动画的变换矩阵
我想获取动画的变换矩阵来计算动画视图的位置。
似乎 Animation 类有一个名为 getTransformation 的方法,可用于获取应用于视图的变换。
但是,如果我在开始动画之前使用 getTransformation,我会获得单位矩阵。如果我这样使用它:
public void onAnimationEnd(Animation animation) {
Transformation t = new Transformation();
animation.getTransformation(animation.getDuration(), t);
}
程序进入无限循环,因为 getTransformation 似乎会触发 onAnimationEnd (为什么?)。
如何使用getTransformation获取动画的变换矩阵?还有其他方法可以做到这一点吗?
I would like to obtain the transformation matrix of an animation to calculate the position of the view that was animated.
It seems the Animation class has a method called getTransformation that can be used to obtain the transformation applied to the view.
However, if I use getTransformation before starting the animation I obtain the identity matrix. And if I use it like this:
public void onAnimationEnd(Animation animation) {
Transformation t = new Transformation();
animation.getTransformation(animation.getDuration(), t);
}
The program enters an infite loop because getTransformation seems to trigger onAnimationEnd (why?).
How should I use getTransformation to obtain the transformation matrix of an animation? Is there another way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为,出于某种原因,这就是 getTransformation 的编码方式。
http:// www.netmite.com/android/mydroid/1.5/frameworks/base/core/java/android/view/animation/Animation.java
看起来你可以检查 hasEnded() 来查看动画是否完成。尝试这样的事情:
Because, for some reason, that is the way getTransformation is coded.
http://www.netmite.com/android/mydroid/1.5/frameworks/base/core/java/android/view/animation/Animation.java
It looks like you can check hasEnded() to see if the animation is complete. Try something like this:
当我想在上一个动画完成后获取下一个动画的 getTransformation() 时,我也遇到了这个问题,然后无限循环导致堆栈溢出。
我从 GrepCode,代码如下
getTransformation()
中,我从来没有发现任何会导致无限循环的问题,因为只有调用onAnimationEnd()
,它才会将mEnded
设置为true。下次调用getTransformation()
时,它应该被if(!mEnded)
阻止,但事实并非如此。这表明 grepcode 的这段代码不正确。事实是,
eEnded = true
是在onAnimationEnd()
调用之后设置的:这应该可以解释为什么会发生无限循环。即使您检查animation.hasEnded()也无济于事,因为它无法将mEnded设置为true。
我解决这个问题的方法是:
在监听器中设置标志以保护:
清除动画监听器。如果需要,我们可以在之后返回
I have met this problem too when I want to getTransformation() for next animation after previous animation done, then infinite loop cause stackoverflow.
I analyzed problem with source code of Android from GrepCode, with codes below in
getTransformation()
, I never find any problem which would cause infinite loop, as only place callonAnimationEnd()
, it will setmEnded
to true. Next time callgetTransformation()
, it should be blocked byif(!mEnded)
, but it's not.It seams grepcode is not correct with this segments of code. The truth is that
eEnded = true
is set afteronAnimationEnd()
called:That should explain why infinite loop happen. Even you check
animation.hasEnded()
would not help, as it could not reach to set mEnded to true.The ways I hack with this problem are:
Set flag in listener to guard:
Clear AnimationListner. If required, we can set back after