views:

496

answers:

1

I would like to be able to alter the size of some of my ImageViews based on what Drawable they are showing. I've not yet decided on whether I'll get them to read the new dimensions from the Drawable or if I will just have an array/enum storing the heights of these, but what I need help with is the actual changing of the ImageView size.

Which of the many many function for altering sizes of things should I be using to change the size of an ImageView while still retaining it's relative positioning in the RelativeLayout it is a part of? I can't work out if I should be changing the bounds of the Drawable or if I should be redefining the LayoutParams of the ImageView or some other method altogether. The drawables are always going to be the same width, but their height will change depending on what is in each tile of a map (which this is rendering).

+1  A: 

Maybe I'm missing something here, but you should probably just use:

<ImageView
    android:id="@+id/image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/image_content"
    />

Using wrap_content will cause the ImageView to assume the shape of whatever drawable you insert.

kcoppock
This is actually where I started and had real issues with things scaling to the wrong relative size, hence the extra complexity.However after you said this I realised I should revisit it and simply adding a maxwidth= made it behave how I wanted. Now they stay the relative width I want, but scale to fit the drawable in the other dimension.
Zulaxia
Glad you got it working! Thinking about it, I've not done anything to change a drawable in code yet, so I don't know how exactly it handles the rescaling.
kcoppock