Search code examples
androidimageimageviewscalegeometry

How to make imageview's background to scale proprtionally in android?


What i need is that image should be scaled till it retains the exact proportions after that it should not be scaled further, so that every time width is equal to height of the image view.

As if don't scale properly it will get out of shape, and i need it to be in 1:1 ratio of width and height.

Will

 Imageview:scale="fitxy"

work in this case ?

Please help thnk you.

I am working on android ICS


Solution

  • To keep aspect ratio, you should make the image the src rather than background.

    Take a look at the ScaleType documentation here http://developer.android.com/reference/android/widget/ImageView.ScaleType.html.

    You should try using either android:scaleType="centerInside" or android:scaleType="centerCrop".

    Hope that helps!