Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ImageView Fixing Image Size

I have an Android Application, where I have an ImageView, I need to keep the size constant, there can be various images that I need to put into this ImageView, of different sizes.

I just need to ensure that all the Images must fit into the ImageView, the Image should increase in size if it is smaller and should decrease, in case it is bigger.

Thanks a lot for your time.

like image 685
Shalabh Avatar asked Aug 21 '12 06:08

Shalabh


People also ask

How do I resize an image in ImageView to keep the aspect ratio?

However, make sure you're setting the image to the ImageView using android:src="..." rather than android:background="..." . src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly to the size of the ImageView.

What is adjust view bounds in android?

android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.


2 Answers

Fix ImageView's size with dp or fill_parent and set android:scaleType to fitXY.

like image 79
Youngsik Oh Avatar answered Oct 12 '22 16:10

Youngsik Oh


In your case you need to

  1. Fix the ImageView's size. You need to use dp unit so that it will look the same in all devices.
  2. Set android:scaleType to fitXY

Below is an example:

<ImageView     android:id="@+id/photo"     android:layout_width="200dp"     android:layout_height="100dp"     android:src="@drawable/iclauncher"      android:scaleType="fitXY"/> 

For more information regarding ImageView scaleType please refer to the developer website.

like image 31
Lazy Ninja Avatar answered Oct 12 '22 17:10

Lazy Ninja