5

LinearLayout从原来的高度重新调整0为:

ViewGroup.LayoutParams params = getLayoutParams();
params.height = newHeight;
requestLayout();

一切正常,除了newHeight = 0- 布局的高度变回原来的高度。我怎样才能避免它?

将可见性设置为GONEifnewHeight == 0没有帮助。

4

5 回答 5

13

试试这个.....

 LinearLayout layout = (LinearLayout)findViewById(R.id.yourLayoutId);

 LinearLayout.LayoutParams lp = (LayoutParams) layout.getLayoutParams();
 lp.height = 0;
于 2012-09-03T10:46:07.300 回答
3
layout = (LinearLayout)findViewById(R.id.linearTop);

layout.getLayoutParams().height =  ViewGroup.LayoutParams.WRAP_CONTENT;                
ViewGroup.LayoutParams params =    layout.getLayoutParams();
params.height =  ViewGroup.LayoutParams.WRAP_CONTENT;
layout.setLayoutParams(params);
于 2015-09-14T11:07:06.780 回答
0

您不必设置params使用setBaseAttributes()的高度吗?int height = ...不会对...产生任何params影响

于 2012-09-03T09:48:16.297 回答
0

你确定你得到的是实际参数对象,而不是一个副本吗?我会尝试以下代码:

ViewGroup.LayoutParams params = getLayoutParams();
params.height = newHeight;
setLayoutParams(params);
requestLayout();
于 2012-09-03T10:27:35.977 回答
0

然后尝试设置一个新的布局参数对象。这应该工作

ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,0);
layout.setLayoutParams(lp);
于 2012-09-03T10:41:33.423 回答