0

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Martin Dusek
  • 1,170
  • 3
  • 16
  • 41

2 Answers2

1

Use attr android:adjustViewBounds="true" in ImageView

I hope this will help you.

Alex Sunder Singh
  • 2,378
  • 1
  • 7
  • 17
0

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

Martin Dusek
  • 1,170
  • 3
  • 16
  • 41