question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

placeholder image and progressbar image are not displayed when using in custom imageview

See original GitHub issue

Hi,

As our UI request, I have to use custom view to use fresco. As your document in your official site. I do the below things. Use the my view, the remote picture was loaded successfully, but it’s displaying empty not the place holder image before remote picture loaded. I am not sure it’s your library’s bug. Can you help look at this? thanks!

  • init code.
public class ChatImageDraweeView extends ImageView {

        private CloseableReference<CloseableImage> imageReference = null;

        public DraweeHolder<GenericDraweeHierarchy> mDraweeHolder;

        public ChatImageDraweeView(Context context) {
            this(context, null);
        }

        public ChatImageDraweeView(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }

        public ChatImageDraweeView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources())
                    .setFailureImage(R.color.img_placehoder_color)
                    .setProgressBarImage(new ProgressBarDrawable())
                    .setProgressBarImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE)
                    .setPlaceholderImage(context.getResources().getDrawable(R.color.img_placehoder_color))
                    .setPlaceholderImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE)
                    .build();
            mDraweeHolder = DraweeHolder.create(hierarchy, context);
        }


-  setImageUrl:

 public void setImageUrl(String url) {
        ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
                .build();
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        final DataSource<CloseableReference<CloseableImage>> dataSource =
                imagePipeline.fetchImageFromBitmapCache(imageRequest, this);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setOldController(mDraweeHolder.getController())
                .setImageRequest(imageRequest)
                .setControllerListener(new BaseControllerListener<ImageInfo>() {
                    @Override
                    public void onFinalImageSet(String s, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
                        try {
                            imageReference = dataSource.getResult();
                            if (imageReference != null) {
                                CloseableImage image = imageReference.get();
                                // do something with the image
                                if (image != null && image instanceof CloseableStaticBitmap) {
                                    CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
                                    Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
                                    if (bitmap != null) {
                                        setImageBitmap(bitmap);
                                    }
                                }
                            }
                        } finally {
                            dataSource.close();
                            CloseableReference.closeSafely(imageReference);
                        }
                    }
                })
                .setTapToRetryEnabled(true)
                .build();
        mDraweeHolder.setController(controller);
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
capricecommented, Jul 1, 2016

@oprisnik Thanks a lot for your detailed explanation. After I added mDraweeHolder.setController(controller)below mDraweeHolder.setController(controller);in my above code, the place holder image is showing correctly.

0reactions
447zygcommented, Jul 25, 2017

thanks very much! @caprice @oprisnik

Read more comments on GitHub >

github_iconTop Results From Across the Web

Glide not loading real image and stuck with placeholder
So the trick is placeholder is set via setImageDrawable() so the ImageView will just display it as usual, but you tell Glide to...
Read more >
Displaying Images with the Picasso Library
Open up your static placeholder or error images in your drawable folders and make sure that the dimensions of the images are relatively...
Read more >
ImageView - Android Developers
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image...
Read more >
How to use AsyncImage in SwiftUI - BLCKBIRDS
In this tutorial, you'll learn everything you need to know about the new AsyncImage in SwiftUI to fetch images in a safe and...
Read more >
Advanced Data Binding in Android: Binding Adapters
This binding adapter receives two attributes: one with the image URL and the other with Drawable that will show as a placeholder while...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found