0
votes

There are many questions about resizing ImageView and while keeping aspect ratio, but I'm not able to manage to resize my ImageView. Is really even Android's ImageView so badly designed, that we can't resize it while keeping aspect ratio. This is my code which doesn't work (I set):

<ImageView
    android:id="@+id/icon"
    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:src="@drawable/sample"/>

My Image is png with approx 200 x 300 px size (the size is varying). I want the ImageView to resize it to 30 dp width, while keeping aspect ratio. FYI: I can't set ImageView's parent dimensions, the parent's dimension are match_parent.

2
if you are setting the width already why not set the height ?Jibran Khan
The height is approx 300 px, but can be anything between 250 and 350 px. Sorry I didn't mention that. Just consider the height unknown.Martin Dusek

2 Answers

0
votes

Use attr android:adjustViewBounds="true" in ImageView

I hope this will help you.

0
votes

This is my mistake: I accidentaly used setBackgroundResource to set my ImageView. One have to use setImageResource.