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?
Asked
Active
Viewed 2.5k times
31
-
1Look at this. here you can find your answer. http://stackoverflow.com/a/2524243/614807 – Chirag Jul 27 '12 at 10:38
3 Answers
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.
-
13This 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
-
3If 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