0

How can I scale an image loading into a DraweeView so that the width is always fitted?

The DraweeView is configured like this:

<com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="match_parent"
        android:layout_height="X dp"/>

with "X dp" meaning some fixed amount of dp. The image's height should be cropped if it doesn't fit in the View.

Eric Brandwein
  • 861
  • 8
  • 23

1 Answers1

0

You can use a scale type for this, see http://frescolib.org/docs/scaling.html

In your case, centerCrop should work:

Add this to your Drawee in XML: fresco:actualImageScaleType="centerCrop"

In Java:

GenericDraweeHierarchyBuilder builder = ... // your builder
builder.setActualImageScaleType(ScaleType.CENTER_CROP);

If you need more complex scaling, you can also implement your own scale type that extends AbstractScaleType and set it in Java.

Alexander Oprisnik
  • 1,212
  • 9
  • 9