AnimationDrawable无法在2.3.6安卓版上运行。
是否有较旧版本的支持库?
我的代码是:
iv = (ImageView) findViewById(R.id.splashnew);
BitmapDrawable f0 = (BitmapDrawable)getResources().getDrawable(R.drawable.s1);
BitmapDrawable f1 = (BitmapDrawable)getResources().getDrawable(R.drawable.s2);
BitmapDrawable f2 = (BitmapDrawable)getResources().getDrawable(R.drawable.s3);
int dur = 850;
AnimationDrawable ad = new AnimationDrawable();
ad.addFrame(f0, dur);
ad.addFrame(f1, dur);
ad.addFrame(f2, dur);
ad.start();
ad.setOneShot(true);
答案 0 :(得分:19)
我得到了答案:
您应该在runnable中启动动画。
iv.post(new Runnable(){
public void run(){
ad.start();
ad.setOneShot(true); // use this if you want to run the animation only once
}
});
答案 1 :(得分:0)
试试这个
iv = (ImageView) findViewById(R.id.splashnew);
BitmapDrawable f0 = (BitmapDrawable)getResources().getDrawable(R.drawable.s1);
BitmapDrawable f1 = (BitmapDrawable)getResources().getDrawable(R.drawable.s2);
BitmapDrawable f2 = (BitmapDrawable)getResources().getDrawable(R.drawable.s3);
int dur = 850;
AnimationDrawable ad = new AnimationDrawable();
ad.addFrame(f0, dur);
ad.addFrame(f1, dur);
ad.addFrame(f2, dur);
iv.setBackgroundDrawable(ad);
iv.post(new Runnable(){
public void rub(){
ad.start();
}
}