Automatic image height with nativescript-fresco plugin

android

#1

I need to have an image stretched to 100% width and automatic height based on image aspect ratio. Is it possible to achieve this?


#2

Yes, it’s possible to show image in aspect ratio with dynamic height. You already have everything explained in the plugin docs.

As documented by the Fresco library setting the height and width are mandatory, more details on this topic could be found here. So the first this you should do when declaring the FrescoDrawee is set its width and height attributes or set only one of them and set the FrescoDrawee’s aspectRatio. The width and height of the FrescoDrawee in your {N} application supports percentages which makes it possible to declare for example width=“50%” and aspectRatio=“1.33” achieving exactly 50% width with dynamically calculated height based on the aspect ration of the loaded image from the imageUri.


#3

width=“50%” and aspectRatio=“1.33” achieving exactly 50% width with dynamically calculated height based on the aspect ration of the loaded image from the imageUri.

Written is “aspect ration of the loaded image”, but in reality it does “aspect ratio given in the aspectRatio parameter”. If the image is wider than the given aspect ratio, it is filled with white color to the given aspect ratio creating a gap over/below.

I need to have the whole image in it’s original aspect ratio, scaled up or down to fit the available width, no cropping, no white filling.


#4

Did you try setting the actualImageScaleType, centerInside or fitCenter may work.


#5

Yes, it doen’t do any difference.