创建动画的ImageView的同时改变图像资源 [英] Creating animation on ImageView while changing image resource

查看:150
本文介绍了创建动画的ImageView的同时改变图像资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个的ImageView 在我的布局,我改变它的资源一个gasture事件检测到。我只是想表明一个动画,同时改变ImageView的资源。我可以使用 ViewFlipper 一个 ImageView的?

I have only one ImageView in my layout and I am changing its resource when a gasture event detected. I just want to show an animation while changing resource of ImageView. Can I use ViewFlipper with one ImageView?

推荐答案

对于单一ImageView的,你可以使用这个辅助函数:

For a single imageview you can use this helper function:

public static void ImageViewAnimatedChange(Context c, final ImageView v, final Bitmap new_image) {
    final Animation anim_out = AnimationUtils.loadAnimation(c, android.R.anim.fade_out); 
    final Animation anim_in  = AnimationUtils.loadAnimation(c, android.R.anim.fade_in); 
    anim_out.setAnimationListener(new AnimationListener()
    {
        @Override public void onAnimationStart(Animation animation) {}
        @Override public void onAnimationRepeat(Animation animation) {}
        @Override public void onAnimationEnd(Animation animation)
        {
            v.setImageBitmap(new_image); 
            anim_in.setAnimationListener(new AnimationListener() {
                @Override public void onAnimationStart(Animation animation) {}
                @Override public void onAnimationRepeat(Animation animation) {}
                @Override public void onAnimationEnd(Animation animation) {}
            });
            v.startAnimation(anim_in);
        }
    });
    v.startAnimation(anim_out);
}

这篇关于创建动画的ImageView的同时改变图像资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆