Reputation: 4780
I'm using Fresco library for loading images and gifs into my application. The big restriction I have encountered with Fresco is that the layout width and height have to be set. So I have set up my simple drawee view like so:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image"
android:layout_marginTop="@dimen/feed_item_margin"
android:scaleType="fitCenter"
fresco:actualImageScaleType="fitStart"
android:layout_below="@+id/content_header"
android:layout_width="match_parent"
android:layout_height="@dimen/texture_view_height"
fresco:placeholderImage="@drawable/placeholder"
/>
My issue is if the image height is greater than the width there is a lot of white space left to the right of the image (see attached), however the height is fine
Then it can happen where the height if the actual image is less than the width (see attached) so here because the fixed height is 250dp there is a lot of white space below the image.
I have been through the different scaleTypes in the SimpleDrawerView and none seem to work to display the way I want to.
I'm wondering does anyone have much experience with Fresco? I've started using this for loading gifs as I had an issue with Glide.
If anyone can help I'd greatly appreciate it.
FYI these images are streamed from a server, I have no control over the images
Upvotes: 3
Views: 3315
Reputation: 1088
I am one of the authors of the Fresco library and I can probably help. From your question I don't actually know how would you like your images to be displayed.
First off, I would strongly suggest that you read the documentation first. You will find that android:scaleType
is completely ignored by Fresco and that you should use fresco:actualImageScaleType
instead.
My issue is if the image height is greater than the width there is a lot of white space left to the right of the image (see attached), however the height is fine.
If the height is fine, how is the extra horizontal space supposed to be populated? These are the only possible options:
actualImageScaleType=centerCrop
)actualImageScaleType=fitXY
)actualImageScaleType=fitCenter
).Then it can happen where the height if the actual image is less than the width (see attached) so here because the fixed height is 250dp there is a lot of white space below the image.
Maybe the following would satisfy you. Set the layout params as following:
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1.33"
fresco:actualImageScaleType="fitCenter"
This will make the drawee view have the width of the parent, and width to height ratio is going to be 1.33 (4:3) by default. Then you can programmatically set the aspect ratio to match the one of the image as I explained in another answer. This will make drawee view height dynamically adjust based on the image.
Upvotes: 7