Solution 1 :
android:layout_width="wrap_content"
android_layout_height="wrap_content"
means that the view will adjust its size in acordance with the content. If you want the image to crop, specify those, e.g.
android:layout_width="40dp"
android_layout_height="40dp"
Solution 2 :
scaleX and scaleY is scalling the image. Removing both will solve your problem. Also give it a fixed height and width.
Edit these lines
android:layout_width="50dp"
android_layout_height="50dp"
And remove these lines
android:scaleX="2"
android_scaleY="2"
Problem :
I am trying to scale an image inside an ImageView, but I want the image to get cropped if it goes outside the view boundaries. This is what it looks like. The image just gets rendered outside the View boundaries. I have tried all the different forms of android:scaleType
and android:adjustViewBounds
but none of them work to keep the image inside those boundaries. Basically what I want to have as an end result is an image that can zoom in and zoom out but when you zoom in, the image gets cropped to fit in the space. Maybe this is one of those things that is just not possible?
Comments
Comment posted by Ritu Suman Mohanty
you gave height and width as wrap_contect.for this it will take the size of the image.you can use static height width for that.
Comment posted by Created
Did you solve the problem?
Comment posted by Caleb W
This didn’t fix the problem. I made the height and width 40dp but the image still can go way beyond that.
Comment posted by Caleb W
Maybe the question is not clear, but I want the image to be scaled up but the outside of the image should be cropped when it goes outside the boundaries of the ImageView.
Comment posted by Osama Muhammad
You can use an image with larger dimensions, and give your image static width and height.
Comment posted by Caleb W
Okay, I edited my question to try to communicate my problem a little bit clearer. I want the image to be able to zoom in and out but get cropped when it enlarges outside the boundaries.