Reputation: 152216
I am resizign LinearLayout
from it's original height to 0
with:
ViewGroup.LayoutParams params = getLayoutParams();
params.height = newHeight;
requestLayout();
Everything works except newHeight = 0
- layout's height changes back to its original height. How can I avoid it ?
Setting visibility to GONE
if newHeight == 0
does not help.
Upvotes: 5
Views: 18941
Reputation: 31
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);
Upvotes: 3
Reputation: 31779
Try setting a new layout params object then. This should work
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,0);
layout.setLayoutParams(lp);
Upvotes: 0
Reputation: 1208
Try this.....
LinearLayout layout = (LinearLayout)findViewById(R.id.yourLayoutId);
LinearLayout.LayoutParams lp = (LayoutParams) layout.getLayoutParams();
lp.height = 0;
Upvotes: 13
Reputation: 3397
Are you sure that you get the actual parameters object, not the copy of one? I would try the following code:
ViewGroup.LayoutParams params = getLayoutParams();
params.height = newHeight;
setLayoutParams(params);
requestLayout();
Upvotes: 0
Reputation: 23655
Wouldn't you have to set the height of params
using setBaseAttributes()? The int height = ...
will not have any influence on params
...
Upvotes: 0