问题
I have an app which loads an image using the fresco library. I have 2 problems. 1. If I use the fresco image like this
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/feedImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
it won't display anything but a thin line of colors where the image should be.
However if I do something like
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/feedImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1.33"
android:scaleType="fitXY"
/>
everything is working fine(but I don't see the full image).
I want to achieve the same view as facebook(images full width and height).
- I load the images in a list in a recycler. The images are loaded into cache(I verified that) but if I go all the way down and then back up I can see the images being loaded(facebook doesn't have this problem and they use the same library). If I scroll really slow there is no problem. I recently changed from volley and I did not have this problem before(so it's not the recycler). How can I solve this ?
Edit: And something else that I noticed is that if I disable the disk cache and kill the app the cache is not deleted as the documentation says. I know that if I call ImagePipeline imagePipeline = Fresco.getImagePipeline(); Uri uri; imagePipeline.evictFromMemoryCache(uri);
the cache will be deleted, but shouldn't this be automatically ?
回答1:
So for problem #2 I am not entirely sure I understand the problem correctly it isnt a problem at all. The image may very well be in memory cache, however the image stored in cache still needs to be decoded before it can be displayed on screen, which is probably that loading issue you speak of. The reason you only see this when scrolling through quickly is because the RecyclerAdapter that you are using is catching up to the scroll position.(this is an educated guess, by no means should this be assumed to be correct). When you move slowly and dont see the image loading is because the Adapter starts to load the next ViewHolder before it is on screen, but not much before that point. SO when you scroll quickly I believe it is simply the Adapter playing catching up with its OnBindViewHolder call, as opposed to moving through slowly it doesnt need to play catch up and has the image loaded before you reach the next item in the recyclerview.
The disk cache is not cleared when the app is backgrounded like memory cache, so if needed you will need to evict it.
I am not sure about issue #1 but I will try to find out why that may be. Maybe try setting the scaletype to CropCenter or something and see if that rids you of the lines.
来源:https://stackoverflow.com/questions/33661308/fresco-image-with-both-width-and-height-match-parent-doesnt-display