0

我正在使用两个空隙来制作动画,因为我需要在同一个屏幕上制作不同的动画。这个动画适用于不同的 ImageViews。当我将这两个 ImageViews 同时添加到主屏幕时。他们开始但落后。但是,如果我对不同的 ImageViews 使用相同的动画,则没有问题。为什么会发生这种滞后我使用线程来调用。只有 2 个 ImageViews 和位图非常小,只有 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();

        }
4

0 回答 0