Question

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 functions for altering sizes of things should I be using to change the size of an ImageView while still retaining its 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).

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top