2

I have a row in a list view with 3 fields. Icon to the left, a header and a description about 3-4 lines below the header. Initially description is hidden. On click of the header the visibility is changed from Gone to Visible or vice versa. When the description is visible, I want to stretch image view (icon) to the height of the expanded row. How do I do this ? I have given

android:layout_height="fill_parent"

android:scaleType="fitXY" to <ImageView />

If I change, height of icon to LayoutParams.FILL_PARENT in the program, the images stretches more than necessary.

Prabhat
  • 2,261
  • 7
  • 46
  • 74

1 Answers1

2

You can try using gravity's FILL, FILL_HORIZONTAL, and FILL_VERTICAL feature. Take a look a this for further detail on this.

A. Abiri
  • 10,750
  • 4
  • 30
  • 31
  • There is no property called android:gravity for ImageView. – Prabhat Jul 29 '11 at 06:29
  • This is what it should look like when you want to make it FILL: `android:layout_gravity="fill"`. You just put that under the layout of the imageview. If you want to make it FILL_VERTICAL or FILL_HORIZONTAL, you do this: `android:layout_gravity="fill_vertical"` or `android:layout_gravity="fill_horizontal"`. – A. Abiri Jul 29 '11 at 07:22
  • I have a relative layout around the listview. If I give android:layout_gravity="fill_vertical" the image is pre-stretched. I want it to stretch to the size of the row when description is displayed after I click on header. – Prabhat Jul 29 '11 at 08:26
  • I found [this](http://stackoverflow.com/questions/2991110/android-how-to-stretch-an-image-to-the-screen-width-while-maintaining-aspect-rat) website that might help you accomplish what you want. – A. Abiri Jul 29 '11 at 20:33
  • 1
    You can also use `android:layout_weight=".70"`, which in this case expands/shrinks the view to fill 70% of the space it is provided. – A. Abiri Jul 29 '11 at 20:45
  • I am using a relative layout. So layout_weight isnt available. I tried using ViewTreeObserver.OnPreDrawListener. I get the new row height here but setting the height of the image using `img.getLayoutParams().height= NEW_HEIGHT` changes the height only when there is a change in row height next time, not until then. – Prabhat Aug 01 '11 at 07:20
  • You could create a linear layout that contains the relative layout. And then set the relative layout to fill its parent. This way you can use the layout_weight feature of a linear layout and you can still use a relative layout for your views. – A. Abiri Aug 01 '11 at 07:23
  • The thing is, I dont want to increase the width at all. Only the height. Giving layout_weight will increase width also. – Prabhat Aug 01 '11 at 07:26
  • What if you set `android:maxWidth="10dip"` to set the maximum width of the layout. That way the layout_weight will only increase the height since it has reached its maximum width. – A. Abiri Aug 01 '11 at 07:31