androidimagefrescoscaletype

How to preserve aspect ratio of overlay image in Fresco


I am trying to set the scale type of an overlay image in Fresco. But there is no field in the SimpleDraweeView to set the scaletype of its overlay image


Solution

  • Fresco currently does not support to set the scale type in XML. You can wrap your overlay Drawable in a ScaleTypeDrawable:

    ScaleTypeDrawable scaledOverlayDrawable = new ScaleTypeDrawable(overlayDrawable, scaleType);
    

    Since API 24 you can also set a custom drawable in XML. If you target versions earlier than that (which I guess you do), you have to set the overlay in Java.

    Maybe we will add support for setting a scale type some time in the future. Pull requests are also welcome :)