Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my ImageView a fixed size regardless of the size of the bitmap

So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:

    <ImageView android:id="@+id/recipeImage"            android:maxHeight="64px"            android:maxWidth="64px"            android:scaleType="centerCrop"            android:layout_width="wrap_content"            android:layout_height="fill_parent"            android:layout_alignParentTop="true"            android:layout_alignParentBottom="true"            android:layout_marginRight="6dip"/> 

But,nothing has worked.

like image 438
chubbsondubs Avatar asked Sep 23 '10 19:09

chubbsondubs


People also ask

How do you change the size of a picture on android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.

What is ImageView in Android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.


1 Answers

Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the px unit - use dp instead, because these are device-independent.

like image 136
mreichelt Avatar answered Sep 29 '22 17:09

mreichelt