How to fade in picture in ImageView loaded from url

后端 未结 2 641
孤独总比滥情好
孤独总比滥情好 2021-02-04 20:56

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.

I kn

相关标签:
2条回答
  • 2021-02-04 21:12

    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) {}
        });
    
    0 讨论(0)
  • 2021-02-04 21:18

    You can use: TransitionDrawable, simple code as follows:

            // Transition drawable with a transparent drwabale and the final bitmap
            final TransitionDrawable td =
                    new TransitionDrawable(new Drawable[] {
                            new ColorDrawable(Color.TRANSPARENT),
                            new BitmapDrawable(mResources, bitmap)
                    });
            // Set background to loading bitmap
            imageView.setBackgroundDrawable(
                    new BitmapDrawable(mResources, mLoadingBitmap));
    
            imageView.setImageDrawable(td);
            td.startTransition(FADE_IN_TIME);
    
    0 讨论(0)
提交回复
热议问题