0

I have an ImageView.
I set it in xml as below: 

<ImageView
    android:id="@+id/background"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

And set image as below:

ImageView background
background.setImageBitmap(bitmap);

But if the ImageView's parent layout narrow down, the IamgeView also narrow down.
And the image was resized.
I want to let it don't resize.
Is it can modify by setScaleType?
Or how to do it?

brian
  • 6,802
  • 29
  • 83
  • 124

2 Answers2

9

Try setting adjustViewBounds parameter to true on the ImageView.

<ImageView
   android:id="@+id/background"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" 
   android:adjustViewBounds="true"/>
Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
3

Why don't you use scaledBitmap like this

Bitmap bMap =   Bitmap.createScaledBitmap(chosenBitmap, needed_width, needed_height, true);
imageView.setImageBitmap(bMap);
Renjith
  • 5,783
  • 9
  • 31
  • 42