6

i am getting bitmap from gallery / camera and trying to fit in to image view of size 200 dp * 200dp

I had to scale the bitmap to get out of memory issues. Now after scaling the image is not exactly fitting imageview.

The width is fine but height is only half. Is there a way to make the bitmap fit imageview without changing imageview size and without strtching image.

fitxy will do but the image is stretched. i followed this answer

Community
  • 1
  • 1
png
  • 4,368
  • 7
  • 69
  • 118

2 Answers2

0

I think you need to create new Bitmap to fit ImageView sizes, and you must need to create new Bitmap proportioanlly, like whatever height it is, width must be in same ratio with height and then you need to set that bitmap there. Another way is give,

android:adjustViewBounds="true"

It will automatically scale the image proportionally.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

If you are looking for a solution using xml, I created a selector and assigned my imageView background to that:

android:background="@drawable/image_selector"

In my selector I setup a bitmap item and set its gravity to "fill":

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

   <item>
       <bitmap android:gravity="fill"
               android:src="@drawable/kitchen_background"/>
   </item>


</selector>
JFreeman
  • 974
  • 1
  • 10
  • 26