Search code examples
androidbitmapimageviewscaletransition

ImageView bitmap is stretched after activity transition


enter image description here

Is there any specific reason why this is happening?

This is the image after the transition happens.


Solution

  • You haven't provided any code to help us diagnose your problem, but your terrifying image (that looks like Jim Carrey) may be related to the tileMode. Your image looks like it's exhibiting clamping.

    Clamping is when the edge color is replicated if the bitmap for an ImageView is smaller in size than the ImageView. These are all the options, along with a suitable picture of Jim:

    • disabled - Do not tile the bitmap. This is the default value.

    disabled

    • clamp - Replicates the edge color.

    clamped

    • repeat - Repeats the bitmap in both direction.

    repeat

    • mirror - Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam.

    mirror

    Since it looks like your Bitmap is smaller than your ImageView and I don't think you actually want to use any tile mode (just use the default of disabled), I'd recommend either:

    A) Use ImageView's setScaleType() so that the Bitmap resizes to fill the ImageView, using the centerCrop value (though check this blog for more examples), or...

    B) Make your Bitmap larger

    (I'd recommend A)