图像查看动画

时间:2011-05-10 05:20:37

标签: android imageview

我正在处理图像动画的连续顺序。这是我的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);
        }
    }  

1 个答案:

答案 0 :(得分: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

                } 
            });