stavros.3p
stavros.3p

Reputation: 2324

adjustViewBounds gives wrong width - Android

I am trying to display an image which will have the width of the parent view and the height will be calculated to keep the aspect ratio.

The problem is that the width of the image expands beyond parent view width, like the image is zoomed.

<com.facebook.drawee.view.SimpleDraweeView
     android:id="@+id/imageview_mainimage"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:adjustViewBounds="true"
     android:scaleType="centerCrop"
/>

How can I fix this?

Upvotes: 0

Views: 266

Answers (1)

TibiG
TibiG

Reputation: 849

This happens because your SimpleDraweeView doesn't have the same aspect ratio as your loaded image, and adding android:scaleType="centerCrop"will make the SimpleDraweeView try to load the content cropping the image to best fit the smallest of the 2 dimensions. You can either expect the image to have a certain ratio fresco:viewAspectRatio="1.33", or use a different option for scaleType

Upvotes: 1

Related Questions