I have a layout whose root ViewGroup has two children only one of which is always visible. The other child’s visibility will be set at runtime to View.GONE when not applicable.
When both children are visible, the heights are set to wrap_content and the layout looks great. The problem is that I’d like to expand the visible view to match_parent when the other is gone.
Is there any way to accomplish this or the equivalent?
You can change any View’s layout like this:
The constructor takes width then height as in:
new LayoutParams(int width, int height).Also there is a LayoutParams class for each type of ViewGroup. Make sure you import the one that refers your particular ViewGroup. So if your ViewGroup is a LinearLayout use:
I’m not certain where you had trouble, but this approach only requires a couple extras lines:
If you hide / show the views multiple times you can save a reference to each LayoutParams object rather than repeatedly creating new objects.