Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent scaling in Android Imageview?

I have an image that is 480 pixels by 40 pixels. I would like to show this image in an ImageView without having it scale to fit.

Ex: If my screen is only 320pixels wide I would like only 320pixels of the image to show on the screen, not have it cram itself into the ImageView (even if it means that the rest of the image gets cut off).

Is there a way to prevent it from scaling to fit?

EDIT: Also, I would like the left side of the image to line up with the left side of the device's screen.

Thanks

like image 996
PaulG Avatar asked Feb 15 '12 15:02

PaulG


1 Answers

Use ScaleType.CENTER, like this in XML:

android:scaleType="center"

This will "center the image in the view, but perform no scaling"

Read more here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

(This is by the way the first hit on googling "imageview scale")

like image 156
nhaarman Avatar answered Nov 06 '22 14:11

nhaarman