Android, hive 动画("Animators may only be run on Looper threads")错误

标签 android animation looper

我有一个以前的项目,在这个项目中我可以一般地使用 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 的变化

谢谢

最佳答案

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

关于Android, hive 动画("Animators may only be run on Looper threads")错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6308453/

相关文章:

android - Android 广播接收器内的线程

android - LocationManager 和 Looper - 每个线程只能创建一个 Looper

android - CountDownTimer: "Can' t 在尚未调用 Looper.prepare() 的线程内创建处理程序”

android - 位图在 onPictureTaken 中裁剪错误

Android ListView 使应用程序崩溃

java - 对 EditText 进行动画处理后,键盘不再平移 View

ios - 视网膜上的核心动画

Android 5.0 不支持 BitmapFactory.Options inPurgeable

android - 尝试使用 adb 推送/安装 .apk 时出错

Android 两个帧数很多的动画