实现播放图片功能,单张图片可加动画

实现播放图片功能,单张图片可加动画


Animation:


首先,创建一个数组来存放图片,:

        int[] imgs = { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,R.drawable.e

};

          实例化ImageView    ,用数组中的图片替换ImageView中的图片

                    imageView1.setImageResource(imgs[i]);

        创建Animation单张图片动画

    

        AlphaAnimation myAnimation_Alpha;

ScaleAnimation myAnimation_Scale;

                myAnimation_Alpha = new AlphaAnimation(1f, 0f);

myAnimation_Alpha.setDuration(3000);

// 缩放

myAnimation_Scale = new ScaleAnimation(1f, 1.4f, 1f, 1.4f,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,

0.5f);

myAnimation_Scale.setDuration(3000);


创建AnimationSet来放Anrmation动画集合

    AnimationSet animation;

                animation.addAnimation(myAnimation_Scale);

animation.addAnimation(myAnimation_Alpha);

启动Animation动画

            imageView1.setAnimation(animation);

判断动画是否执行完毕   实现方法

                animation.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) {

init();

}

});

如需看全部Demo    请到http://download.csdn.net/detail/qq_26470369/8748803下载


你可能感兴趣的:(图片,animation,图片播放)