2011-05-10 184 views
0

我正在處理圖像動畫的順序。這是我的java活動文件。圖片查看動畫

對於每個imageview我使用fadein,fadeout xml。但我無法通過線程方式逐個獲取這些動畫。

package com.cardio.android; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 

public class guide extends Activity { 

     //create name of animation 
    Animation myFadeInAnimation; 
    Animation myFadeOutAnimation; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    //grab the imageview and load the animations 
     ImageView myImageView = (ImageView) findViewById(R.id.imageView1); 
     ImageView myImageView1 = (ImageView) findViewById(R.id.imageView2); 
     ImageView myImageView2 = (ImageView) findViewById(R.id.imageView3); 
     ImageView myImageView3 = (ImageView) findViewById(R.id.imageView4); 
     ImageView myImageView4 = (ImageView) findViewById(R.id.imageView5); 
     Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein); 
     Animation myFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeout); 
     Animation myFadeInAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadein1); 
     Animation myFadeOutAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadeout1); 
     Animation myFadeInAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadein2); 
     Animation myFadeOutAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadeout2); 
     Animation myFadeInAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadein3); 
     Animation myFadeOutAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadeout3); 
     Animation myFadeInAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadein4); 
     Animation myFadeOutAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadeout4); 



    //fade it in, and fade it out. 
     myImageView.startAnimation(myFadeInAnimation); 
     myImageView.startAnimation(myFadeOutAnimation); 
     myImageView1.startAnimation(myFadeInAnimation1); 
     myImageView1.startAnimation(myFadeOutAnimation1); 
     myImageView2.startAnimation(myFadeInAnimation2); 
     myImageView2.startAnimation(myFadeOutAnimation2); 
     myImageView3.startAnimation(myFadeInAnimation3); 
     myImageView3.startAnimation(myFadeOutAnimation3); 
     myImageView4.startAnimation(myFadeInAnimation4); 
     myImageView4.startAnimation(myFadeOutAnimation4); 
     } 
    } 
+0

Ammmmm有沒有例外?我們可以看到你的動畫文件嗎? – 2011-05-10 06:57:36

+0

fadein.xml <?xml version =「1.0」encoding =「UTF-8」?> 2011-05-10 09:57:26

+0

fadeou.xml <?xml version =「1.0」encoding =「UTF-8」?> 這是我的動畫xml ...請讓我沒有任何錯... – 2011-05-10 10:13:14

回答

0

您需要使用onAnimationEnd事件並在其中觸發下一個動畫。你可以創建一個循環來做到這一點,或者將它們嵌套在一起:

 myAnimation.setAnimationListener(new AnimationListener() { 
       public void onAnimationEnd(Animation animation) { 

        //here enter code for the next animation... 

       } 

       @Override 
       public void onAnimationRepeat(Animation animation) { 
        // TODO Auto-generated method stub 

       } 

       @Override 
       public void onAnimationStart(Animation animation) { 
        // TODO Auto-generated method stub 

       } 
      });