0

I spent several hours trying to do this, but finally I gave up.

I have a LinearLayout. Inside of it I have another LinearLayout that is initially hidden. When some condition occurs, I need that hidden layout to be shown and the containing layout to expand its height in order to show the shown layout.

I can detect that the layout is shown, however, containing layout does not expand. The problem is that after containing layout is another layout that I need to be moved down so that the new layout can be seen.

This I have done at last:

                                sublay.setVisibility(View.VISIBLE);
                                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
                                layout.setLayoutParams(lp);
                                layout.requestLayout();

Of course, that did not work. How can I do it?

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • http://stackoverflow.com/questions/6798867/android-how-to-programmatically-set-the-size-of-a-layout have you gone through this question – soumya sambit Kunda Oct 24 '15 at 04:28
  • Yes.. it did not work... it is strange though that layout.getLayoutParams().height is -1 initially – jstuardo Oct 24 '15 at 04:48
  • have you added height and width property initially to your xml design where you are adding visibility = false ? – soumya sambit Kunda Oct 24 '15 at 04:53
  • it is showing -1 means you have not added height and width in xml – soumya sambit Kunda Oct 24 '15 at 04:55
  • I have created container layout programmatically, not by XML, and I did: final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); for it – jstuardo Oct 24 '15 at 04:58
  • And this for hidden layout: final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); – jstuardo Oct 24 '15 at 05:00
  • is your container layout is a linear layout ? – soumya sambit Kunda Oct 24 '15 at 05:05
  • LinearLayout.LayoutParams.WRAP_CONTENT add this to your container layout and a scrollview to see if it is working correctly – soumya sambit Kunda Oct 24 '15 at 05:06
  • maybe, you just misspelled, and you needed to call sublay.setLayoutParams(lp); sublay.requestLayout(); instead of layout.setLayoutParams(lp); layout.requestLayout(); – Vitaly Zinchenko Oct 24 '15 at 05:38
  • no....sublay has already params set as I wrote in the comment. What i need to do is to increase the container layout height because sublay was correctly height set. I can verify that because if I set the container layout height when I created it, height is correctly set and I can see sublay. – jstuardo Oct 24 '15 at 13:27

1 Answers1

1

Try sublay.getLayoutParams().height = MATCH_PARENT; sublay.getLayoutParams().width = MATCH_PARENT;

Tim Sanch.
  • 81
  • 3