Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ImageView auto-resizing

I want to put and ImageView with a large Y margin on my screen device, which would imply that part of the image would be out of screen, and then that the image would be cropped.

The problem is that Android is scaling the image all the time, so that it fits inside the screen, but I don't want that, I want the image to be cropped.

How can I force the ImageView to be cropped and not resized?

P.S. I tried all the possible ScaleType properties and none of them worked for me!

Code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="200dp"
    android:background="@drawable/my_image"
    android:scaleType="centerCrop"
    />      

</RelativeLayout>
like image 437
thomaus Avatar asked Jul 18 '26 15:07

thomaus


1 Answers

Try replacing android:background with android:src.

like image 83
J.-B. C. Avatar answered Jul 20 '26 03:07

J.-B. C.