我使用两个空隙来制作动画,因为我需要在同一个屏幕上使用不同的动画。而这个动画适用于不同的ImageViews。当我将这两个ImageView同时添加到主屏幕时。他们开始但落后。但如果我使用相同的动画不同的ImageViews没有问题。为什么这个滞后发生我使用线程来调用。只有2个ImageView和位图非常小,只有3帧。
修改 这是一个从eclipse到android studio的导出项目。我只是在android studio中打开一个新的空项目,然后复制粘贴所有代码和资源,而不是没有任何问题。
final RelativeLayout btt = (RelativeLayout) findViewById(R.id.bottomlinear);
class MyThread implements Runnable {
public MyThread() {
ImageView myImage3 ;
myImage3 = getimage( 0,btt.getHeight(),700);
startAnimation(myImage3);
btt.addView(myImage3);
}
public void run() {
}
}
Runnable r = new MyThread();
new Thread(r).start();
class MyThread implements Runnable {
public MyThread() {
ImageView myImage4 ;
myImage4 = getimage( 0,btt.getHeight(),900);
startAnimation1(myImage4);
btt.addView(myImage4);
}
public void run() {
}
}
Runnable r = new MyThread();
new Thread(r).start();
private void startAnimation(ImageView img)
{
AnimationDrawable mframeAnimation = null;
BitmapDrawable frame1 = (BitmapDrawable) getResources().getDrawable(R.drawable.aa);
BitmapDrawable frame2 = (BitmapDrawable) getResources().getDrawable(R.drawable.bb);
BitmapDrawable frame3 = (BitmapDrawable) getResources().getDrawable(R.drawable.cc);
// Get the background, which has been compiled to an AnimationDrawable object.
int reasonableDuration = 10;
mframeAnimation = new AnimationDrawable();
mframeAnimation.setOneShot(false); // loop continuously
mframeAnimation.addFrame(frame1, reasonableDuration);
mframeAnimation.addFrame(frame2, reasonableDuration);
mframeAnimation.addFrame(frame3, reasonableDuration);
img.setBackground(mframeAnimation);
mframeAnimation.setVisible(true,true);
mframeAnimation.start();
}
private void startAnimation1(ImageView img)
{
AnimationDrawable mframeAnimation1 = null;
BitmapDrawable frame1a = (BitmapDrawable) getResources().getDrawable(R.drawable.d);
BitmapDrawable frame2a = (BitmapDrawable) getResources().getDrawable(R.drawable.e);
BitmapDrawable frame3a = (BitmapDrawable) getResources().getDrawable(R.drawable.f);
// Get the background, which has been compiled to an AnimationDrawable object.
int reasonableDuration = 10;
mframeAnimation1 = new AnimationDrawable();
mframeAnimation1.setOneShot(false); // loop continuously
mframeAnimation1.addFrame(frame1a, reasonableDuration);
mframeAnimation1.addFrame(frame2a, reasonableDuration);
mframeAnimation1.addFrame(frame3a, reasonableDuration);
img.setBackground(mframeAnimation1);
mframeAnimation1.setVisible(true,true);
mframeAnimation1.start();
}