AnimationDrawable不打 [英] AnimationDrawable not playing
问题描述
所以,我希望我的动画,只要活动启动时创建的,但由于某种原因,不管我怎么努力会得到它开始。我可以得到它首先有一个click事件,但我希望它启动所有自己。
So I want my animation to start as soon as the activity is created, but for some reason no matter what I try will get it to start. I can get it to start by having a click event but I want it to start all on its own.
下面是我有什么,我如何得到这个工作?
Here's what I have and how do I get this to work?
package tween.learn;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class Animate extends Activity {
public ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView tweenImage = (ImageView) findViewById(R.id.imageView1);
tweenImage.setBackgroundResource(R.anim.cubicfacetween);
AnimationDrawable frameAnimation =
(AnimationDrawable) tweenImage.getBackground();
frameAnimation.start();
}
}
感谢
推荐答案
我觉得你有问题的看法初始化后,开始在动画完成。你应该能够做这样的事情:
I think you have to start the animation after initialization of the view in question is complete. You should be able to do something like:
final ImageView tweenImage = (ImageView) findViewById(R.id.imageView1);
tweenImage.setBackgroundResource(R.anim.cubicfacetween);
tweenImage.post(new Runnable() {
@Override
public void run() {
AnimationDrawable frameAnimation =
(AnimationDrawable) tweenImage.getBackground();
frameAnimation.start();
}
}
修改 - 这个问题使我相信, onWindowFocusChanged
方法并不总是有效。它似乎简单,可能是一个更好的主意,如果你的作品。
Edit - this question led me to believe that the onWindowFocusChanged
method won't always work. It does seem simpler and is probably a better idea if it works for you.
这篇关于AnimationDrawable不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!