0

I have an ImageView and I need to load jpg image from SD card into this view. I have following code:

mImageView.setImageBitmap(SDCardUtilities.getBitmapFromSDCard(item));

getBitmapFromSDCard is my function that only make Bitmap from file on sdcard. But often an image is small and doesn't fill the ImageView fully. How can I stretch the image that it will be fill whole ImageView?

user
  • 86,916
  • 18
  • 197
  • 190
user1166635
  • 2,741
  • 6
  • 22
  • 32

4 Answers4

3
imageView.setScaleType(ScaleType.FIT_XY);

this will make image fill the container

Mayank
  • 8,777
  • 4
  • 35
  • 60
2

Have a look at the android:scaleType value for the ImageView object.

This link may answer your question better: How to scale an Image in ImageView to keep the aspect ratio

Community
  • 1
  • 1
Aldryd
  • 1,456
  • 1
  • 11
  • 7
2

Try something like this:

mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
mImageView.setImageBitmap(SDCardUtilities.getBitmapFromSDCard(item));

I didn't personally test this, but I'm pretty sure that it will do what you want. If it doesn't, let me know your results and we can adjust it.

BTW, I found this information here and you can see a list of possible values that can be passed to setScaleType here.

DavidDraughn
  • 1,110
  • 1
  • 8
  • 15
0

Never having tried this, i'd say: Set the scaletype for your ImageView, try FIT_CENTER for example.

Bondax
  • 3,143
  • 28
  • 35