31

Is there any concept related to IPhone Aspect Fill within Android.I want to include this same concept on my android image on imageview. Please give me the code snippet for this concept?

okay_google
  • 339
  • 4
  • 17
ADIT
  • 2,388
  • 9
  • 34
  • 46

3 Answers3

78

If you want an ImageView that both scales up and down while keeping the proper aspect ratio, add this to your XML:

android:adjustViewBounds="true"
android:scaleType="centerCrop"

Look this.

Community
  • 1
  • 1
Chirag
  • 56,621
  • 29
  • 151
  • 198
  • 13
    This answer is not correct as "fitCenter" does not provide same behaviour than iOS "Aspect Fill". You need to use scaleType="centerCrop" instead. – Christophe Fondacci Apr 06 '14 at 03:58
  • 2
    Does not fill the screen properly – inVINCEable Jan 08 '15 at 16:44
  • 3
    If Anybody is Looking for a property that is similar to Apsect FIt in ios (that is image will maintain its aspect ratio and would fit at least one of (X or y)) then android:scaleType = "fiteCenter" would do. – B.shruti May 16 '18 at 07:30
29

I tried fitCenter and it did not work, I ended up using

android:scaleType="centerCrop"
android:adjustViewBounds="true"
inVINCEable
  • 2,167
  • 3
  • 25
  • 49
zambono
  • 1,397
  • 1
  • 17
  • 26
3

Tested!!! adjustViewBounds needs to be false along with scaleType centerCrop to match UIViewContentModeScaleAspectFill behavior of iOS

android:adjustViewBounds="false"
android:scaleType="centerCrop"
Roohul
  • 1,009
  • 1
  • 15
  • 26