views:

107

answers:

1

I have a custom View class in my app that I'm using in xml layouts. Wherever I'm using this view in my xml, I don't want it to stretch it's container, but I want it to fill out whatever space is available. Here's an example to make it a little clearer. I have a LinearLayout set to horizontal orientation with my custom view followed by a TextView. The TextView is going to stretch the LinearLayout so that it takes up the space it needs and no more. I want my custom view to take up the vertical space that the TextView has made available. Let's say the TextView ends up being 50px tall because of it's contents. The LinearLayout is thus stretched to about this height (not taking into account any margins or padding), so I just want the view to know it can stretch to that height and not "push on" its container.

Without overriding any of the measurement methods of the base class (onMeasure, etc) my View is actually stretching to take up as much space as possible. I have already played around with wrap_content and fill_parent a bunch, so I'm assuming I need to do something in one of the View class' measure methods.

A: 

Does your view supports weight attribute ? http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html You probably can look at android src for LinearLayout to figure this one out.

Alex Volovoy
I don't think that has anything to do with it. I'm using the weight attribute already to evenly share the horizontal space, but I don't see how that's going to affect the vertical space it takes up in a horizontal LinearLayout. if I'm mistaken, please clarify
Rich
sorry didn't read carefully enough and didn't realized that you're talking vertical
Alex Volovoy