tags:

views:

132

answers:

1

Hi,

Can you please tell me how can I setHeight for a ViewGroup? I see there is a layout(l,t,r,b);

But that is different form setHeight(), since I don't know where should be the top/bottom of the viewGroup. I need to set the height of the ViewGroup and return that to ListAdapter.

Thank you.

A: 

You can try using setLayoutParams()

myViewGroup.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));

See here the descriptions of the parameters to LayoutParams

public ViewGroup.LayoutParams (int width, int height)    

Creates a new set of layout parameters with the specified width and height.

width the width, either FILL_PARENT, WRAP_CONTENT or a fixed size in pixels
height the height, either FILL_PARENT, WRAP_CONTENT or a fixed size in pixels
ccheneson
What if my parent height is "wrap_content"? Is there a way to layout my Viewgroup with a specified height?
michael
LayoutParams accepts FILL_PARENT, CONTENT_WRAP or a fixed size in pixel. So you can try myViewGroup.setLayoutParams(new LayoutParams(100,200))
ccheneson