【问题标题】:how to start animation one after the another using thread for image view?如何使用线程进行图像视图一个接一个地启动动画?
【发布时间】:2013-08-28 14:31:15
【问题描述】:

在我的 android 应用程序中,我需要一个接一个地为图像视图设置动画,我有四个图像视图动画应该一个接一个地进行图像视图

我尝试过使用线程

            iv1=(ImageView)findViewById(R.id.imageView1);
    iv2=(ImageView)findViewById(R.id.imageView2);
    iv3=(ImageView)findViewById(R.id.imageView3);
    iv4=(ImageView)findViewById(R.id.imageView4);
    iv1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            animSlideUp = AnimationUtils.loadAnimation(getApplicationContext(),
                    R.anim.slide_up);
            mSplashThread1 =  new Thread(){
                @Override
                public void run(){
                    try {
                        synchronized(this){
                            // Wait given period of time or exit on touch
                            wait(5000);
                            iv3.startAnimation(animSlideUp);
                        }
                    } 
                    catch(InterruptedException ex){                 
                    }

                    finish();

                }
            };
            // The thread to wait for splash screen events
            mSplashThread =  new Thread(){
                @Override
                public void run(){
                    try {
                        synchronized(this){
                            // Wait given period of time or exit on touch
                            wait(5000);
                            iv2.startAnimation(animSlideUp);
                        }
                    } 
                    catch(InterruptedException ex){                 
                    }

                    finish();
                    mSplashThread1.start();             
                }
            };

            mSplashThread.start();
            // The thread to wait for splash screen events

我使用了两个线程来启动动画 请帮助我,我是 android 新手

【问题讨论】:

    标签: android multithreading animation view imageview


    【解决方案1】:

    你可以使用不同的值

    android:startOffset="100"
    

    在 res/anim 文件夹下的动画 xml 文件中,所有四个动画都具有您要使用的延迟(以毫秒为单位)值。如果您需要有关如何使用 xml 动画的帮助,here 是一个供您参考的教程。

    【讨论】:

      【解决方案2】:

      您可以使用AnimationListener。 试试下面的代码:

             @Override
             public void onClick(View v) {
      
                  animSlideUp = AnimationUtils.loadAnimation(getApplicationContext(),
                          R.anim.slide_up);
      
                  animSlideUp.setAnimationListener(new AnimationListener() {
      
                      @Override
                      public void onAnimationStart(Animation animation) {
                          // TODO Auto-generated method stub
      
                      }
      
                      @Override
                      public void onAnimationRepeat(Animation animation) {
                          // TODO Auto-generated method stub
      
                      }
      
                      @Override
                      public void onAnimationEnd(Animation animation) {
                           animSlideUp.setAnimationListener(null);
                           iv3.startAnimation(animSlideUp);
      
                      }
                  });
      
                  iv2.startAnimation(animSlideUp);
      
              }
      

      【讨论】:

      • 我尝试开始,但动画是并行的,它应该一个接一个地开始
      • 尝试编辑后的答案。无需使用线程来延迟动画。您也可以在xml中定义动画偏移值来延迟它。
      猜你喜欢
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 2017-10-26
      相关资源
      最近更新 更多