1

I have a RecyclerView using it as a grid. In each view, I am loading an image from a URL. I tried with Picasso, Fresco and Glide. I have only one issue with all these libraries that is, the images are stretched. This is because of the sizes of the images are different. I am providing the sample of my SimpleDraweeView.

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/sdvRestaurant"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_120sdp"
    app:actualImageResource="@drawable/bg_city"
    app:actualImageScaleType="fitXY"
    android:adjustViewBounds="true"
    android:background="@color/card_shadow_2"/>

My question is, what is the proper way to avoid this image stretching issue? I am thinking that it is not possible to change the size of the image. Scale type that I tried is fitXY which did not help. Also, centerCrop attribute crops my original image. Please give some hint to solve this. Thanks in advance.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
Amsheer
  • 7,046
  • 8
  • 47
  • 81

1 Answers1

1

You are using a fixed height for your images which causes the image to be stretched to that size. I suppose it is necessary for you to have the fixed size of each image as you are showing them in a grid. However, you can set the overall container of the layout to have a fixed height while you might have the image height to wrap_content. Here is what you might consider trying.

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/sdvRestaurant"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:background="@color/card_shadow_2"
    android:src="@drawable/bg_city" />

Please check that I have set the layout_height to wrap_content and set the scaleType to fitCenter. Hope that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • I have one doubt with this. If we use wrap_content then the height of the one row is differ from other right? – Amsheer Dec 09 '18 at 08:51
  • I think I have taken that into my concern in the answer. There is a parent layout of your list item right? Set the height constraints to that parent layout which might be a `LinearLayout` or a `RelativeLayout`. Please let me know if you have any other confusion. – Reaz Murshed Dec 09 '18 at 11:06