如何为ViewGroup设置高度

mic*_*ael 2 android

你能告诉我怎样才能为ViewGroup设置高度?我看到有一个布局(l,t,r,b);

但是这与setHeight()不同,因为我不知道viewGroup的顶部/底部应该在哪里.我需要设置ViewGroup的高度并将其返回到ListAdapter.

谢谢.

cch*_*son 6

你可以尝试使用 setLayoutParams()

myViewGroup.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
Run Code Online (Sandbox Code Playgroud)

请参阅此处对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 MATCH_PARENT, WRAP_CONTENT or a fixed size in pixels
height the height, either MATCH_PARENT, WRAP_CONTENT or a fixed size in pixels
Run Code Online (Sandbox Code Playgroud)