I'm using two voids to make animation because i need diffrent animations in same screen. And this animations for different ImageViews. When i add this two ImageViews at the same time to main screen. They start but lagging. But if i use same animation for diffrent ImageViews there is no problem. Why this lagging happens I use threads to call. Just 2 ImageViews and bitmaps is very tiny and just 3 frames.
EDIT: it was an exported project from eclipse to android studio. I just open new empty project in android studio and copy paste all codes and resources manualy than it just works without any problem.
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();
}