placeholder image and progressbar image are not displayed when using in custom imageview
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@oprisnik Thanks a lot for your detailed explanation. After I added
mDraweeHolder.setController(controller)
belowmDraweeHolder.setController(controller);
in my above code, the place holder image is showing correctly.thanks very much! @caprice @oprisnik