1

I want to fit image to android imageview without preserving the aspect ratio. I.e. I want the image to resize to imageview's size. I know that I can use the image as a background of the imageview to achieve the purpose. But is there any way I can use it as a foreground image of the imageview and fitting it to its dimension?

I have seen various answers and all of them suggest the other thing(image view fitting to the image size).I want to do it via xml.

rahulserver
  • 10,411
  • 24
  • 90
  • 164
  • 1
    Of course, you have tried `android:scaleType="fitXY"`, I suppose... http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – Phantômaxx Apr 26 '14 at 12:22
  • @BobMalooga great! Thank you. It works for me. You can give this as the answer! I am surprised that I could not find a matching answer/hint on SO. – rahulserver Apr 26 '14 at 12:27

1 Answers1

3

Of course, you have tried

android:scaleType="fitXY"

I suppose...

Developer - Scale Type

This would scale in both directions (X, Y) independently (by using the FILL algorhithm, which is - more or less, the same as what it does when setting a background).

Koekiebox
  • 5,793
  • 14
  • 53
  • 88
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Thanks for this answer! Works like a gem! Just hyperlinked that developer.android.com link as an edit. – rahulserver Apr 26 '14 at 12:32
  • I'm happy to contribute. Now, may I know what's wrong in using the background? Just for curiosity - you might answer: "I use the background and the src is semitransparent (or has transparent parts)" – Phantômaxx Apr 26 '14 at 12:36