Android,蜂窝动画(“动画器只能在 Looper 线程上运行”)错误

发布于 2024-11-14 18:58:55 字数 1148 浏览 4 评论 0原文

我以前有一个项目,在该项目中,我通常可以使用 ObjectAnimator 类来为任何像这样的类设置动画

ObjectAnimator oa = ObjectAnimator.ofFloat(testShape, "translateX", 0f, 000f);
oa.setDuration(1000l);
oa.setRepeatCount(ObjectAnimator.REVERSE);
oa.setRepeatMode(ObjectAnimator.RESTART);
oa.start();

……并且运行得很好,没有任何问题。现在,当我尝试运行相同的设置时,

W/dalvikvm(19053): threadid=10: thread exiting with uncaught exception (group=0x400d1760)
E/AndroidRuntime(19053): FATAL EXCEPTION: Animation Thread
E/AndroidRuntime(19053): android.util.AndroidRuntimeException: Animators may only be run on Looper threads
E/AndroidRuntime(19053):    at android.animation.ValueAnimator.start(ValueAnimator.java:900)
E/AndroidRuntime(19053):    at android.animation.ValueAnimator.start(ValueAnimator.java:931)
E/AndroidRuntime(19053):    at android.animation.ObjectAnimator.start(ObjectAnimator.java:282)
E/AndroidRuntime(19053):    at com.processing.test.Run.setup(Run.java:43)

我尝试在绘制循环中添加 Looper.prepare() 和 Looper.loop() 但无济于事。因为我以前根本没有使用过 Looper 类,所以这是一种不受欢迎的方法。

这可能是我的底层库(在本例中为processing-android)的版本问题,还是由于 Honeycomb 从 3.0 更改为 3.1,

谢谢

I had a previous project in which I could generically use the ObjectAnimator class to animate any class like this

ObjectAnimator oa = ObjectAnimator.ofFloat(testShape, "translateX", 0f, 000f);
oa.setDuration(1000l);
oa.setRepeatCount(ObjectAnimator.REVERSE);
oa.setRepeatMode(ObjectAnimator.RESTART);
oa.start();

...and that would run great, no issues. Now when i try to run the same setup i get

W/dalvikvm(19053): threadid=10: thread exiting with uncaught exception (group=0x400d1760)
E/AndroidRuntime(19053): FATAL EXCEPTION: Animation Thread
E/AndroidRuntime(19053): android.util.AndroidRuntimeException: Animators may only be run on Looper threads
E/AndroidRuntime(19053):    at android.animation.ValueAnimator.start(ValueAnimator.java:900)
E/AndroidRuntime(19053):    at android.animation.ValueAnimator.start(ValueAnimator.java:931)
E/AndroidRuntime(19053):    at android.animation.ObjectAnimator.start(ObjectAnimator.java:282)
E/AndroidRuntime(19053):    at com.processing.test.Run.setup(Run.java:43)

I have tried to add the Looper.prepare() and Looper.loop() in my draw loops but to no avail. Since I haven't had to use the Looper class at all previously though, this is an undesired approach.

Could this be a version issue with my underlying lib (processing-android in this case) or is it due to a change in Honeycomb from 3.0 to 3.1

thanks

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

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

发布评论

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

评论(1

梦与时光遇 2024-11-21 18:58:55

查看 ObjectAnimator 的文档,情况似乎没有发生变化:您可能只需要确保从 UI 线程进行调用:要么确保在事件处理程序方法中调用它,要么使用处理程序实例或使用实际运行动画的 Runnable 执行 View.post() 。您是否突然开始从不同位置调用 start

Looking at the docs for ObjectAnimator it doesn't appear that things changed: what you probably just need to do is make sure you are making the call from the UI thread: either make sure it is being called in an event handler method, use a Handler instance or do View.post() with a Runnable that actually runs the animation. Did you suddenly start invoking start from a different location?

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