I have this ImageView
<ImageView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/offer_img" />
I'm loading images into this ImageView from a URL and I want the image to always fit X (width of the screen) and readjust the height to keep the aspect ratio. Do I need some Java to do this or can I do it through XML alone?
Try this:
<ImageView
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/offer_img" />
You will obtain what you expect only if original image ratio is around the 8:5 ratio
You could try it with android:scaleType
You could use the method that is the answer in this question: Java image resize, maintain aspect ratio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With