Android 是否有一个';打火机&x27;解决此自定义AnimationRunnable的方法?
我已经研究这个问题好几天了,一直无法解决这个问题 我有许多动画都是作为可运行的实现的,当用户使用应用程序时,这些动画将持续运行。有4种不同的动画,从logo_animation000到115,从z_animation000到515:Android 是否有一个';打火机&x27;解决此自定义AnimationRunnable的方法?,android,Android,我已经研究这个问题好几天了,一直无法解决这个问题 我有许多动画都是作为可运行的实现的,当用户使用应用程序时,这些动画将持续运行。有4种不同的动画,从logo_animation000到115,从z_animation000到515: ConnectionAnimation(在应用程序连接到设备时运行) ConnectionCompleteAnimation(连接完成后运行一次) TransitionOnSleepingAnimation(当应用程序的状态更改时运行一次) SleepingAni
- ConnectionAnimation(在应用程序连接到设备时运行)
- ConnectionCompleteAnimation(连接完成后运行一次)
- TransitionOnSleepingAnimation(当应用程序的状态更改时运行一次)
- SleepingAnimation(在应用程序的状态为“睡眠”时运行)
abstract class MyAnimationRunnable implements Runnable {
protected final int interval;
protected final String pattern;
protected final OptimisedImageView view;
protected long firstFrameAt;
protected int current;
protected Drawable drawable;
protected int frameCounter = 0;
public MyAnimationRunnable(int interval, int firstFrame, String pattern, OptimisedImageView view) {
this.interval = interval;
this.pattern = pattern;
this.view = view;
this.current = firstFrame;
this.firstFrameAt = SystemClock.elapsedRealtime();
handler.post(this);
}
@Override
public void run() {
final String name = String.format(Locale.ENGLISH, pattern, current);
final int id = getResources().getIdentifier(name, "drawable", getPackageName());
if (id != 0) {
final Drawable drawable = getResources().getDrawable(id);
view.setImageDrawable(drawable);
}
current++;
if (runAgain()) {
frameCounter++;
long nextAt = firstFrameAt + (frameCounter * interval);
long delay = nextAt - SystemClock.elapsedRealtime() - 1;
if (delay > 0) {
handler.postDelayed(this, delay);
} else {
this.run();
}
}
}
protected abstract boolean runAgain();
};
private void startSleepingAnimation()
{
zzzAnimation = new MyAnimationRunnable(50, 1, "z_animation%04d", zzzImageView) {
@Override
protected boolean runAgain() {
if (current == 510) {
current = 470; // this seems to fit into the infinite loop.
}
return true;
}
};
}
private void startConnectingAnimation() {
handler.removeCallbacks(connectingCompleteAnimation);
handler.removeCallbacks(zzzAnimation);
handler.removeCallbacks(transitionToSleepingAnimation);
connectingResourceCount = 1;
zzzImageView.setImageBitmap(null);
connectingAnimation = new MyAnimationRunnable(50, connectingResourceCount, "logo_animation%04d", babyImageView) {
@Override
protected boolean runAgain() {
if (current == 30) {
current = 1;
}
connectingResourceCount = current;
return true;
}
};
}
// The remaining two animations have been left out since this oughta be sufficient for understanding the code.
这在我的三星Galaxy S3上运行正常。但是在较旧的手机上,这会在20-30秒后导致崩溃。关于如何使代码更轻、更高效,有什么想法吗?请发布logcat堆栈跟踪。可能延迟总是很有趣的。这可能解释了我测试的Sony Xperia上应用程序的一些行为。你对我能做些什么来解决这个问题有什么建议吗?除了什么例外,这个应用程序会在旧手机上崩溃?