如何在从URL加载的ImageView中淡入图片 [英] How to fade in picture in ImageView loaded from url

查看:65
本文介绍了如何在从URL加载的ImageView中淡入图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将淡入动画应用于ImageView,以创建一种效果,即从URL加载的图像在下载完成后会淡入.

I would like to apply a fade-in animation to an ImageView to create the effect that the image, which is loaded from a url, fades in when the download is completed.

我知道如何从url下载图像到ImageView,就像在像这里一样.

I know how to download an image from a url to an ImageView, like in this answer, and I know how to apply a fade-in animation to an imageView like here.

这次尝试

Drawable d = ImageUtils.fetchDrawable("the url");
imageView.setImageDrawable(d);
imageView.startAnimation(fadeInAnimation);

产生眨眼效果(看不见,淡入看).反转最后两行的顺序也会导致闪烁.

results in a blink effect (see, not see, fade in to see). Reversing the order of the two last lines also results in a blink.

我已经在Google上搜索并以回调/侦听器的形式搜索解决方案-像这样:

I've googled and searched SO for a solution in the form of a callback / listener - something like this:

imageView.setOnLoadCompleteListener...

在ImageView中注册加载完成事件,但是我没有发现任何内容.

to register the loading complete event in ImageView but I haven't found anything along those lines.

对于能实现这种效果的解决方案的任何指示,我将不胜感激.

I'd be grateful for any pointers to a solution on how to implement this effect.

推荐答案

ImageView可见性设置为INVISIBLEGONE 在动画上设置setAnimationListener.以及onAnimationEnd更改ImageView的可见性时.

set the ImageView visibility to INVISIBLE or GONE set setAnimationListener on your animation. and when the onAnimationEnd change the visibility of the ImageView.

fadeInAnimation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {

           // let make your image visible


        }

        @Override
        public void onAnimationRepeat(Animation animation) {}
        @Override
        public void onAnimationStart(Animation animation) {}
    });

这篇关于如何在从URL加载的ImageView中淡入图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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