Changing orientation of all children of LinearLayout programatically

Viewed 1232

I have a LinearLayout (child) inside another (parent) LinearLayout. I want to change the orientation of the parent from horizontal to vertical and vice versa and do the same for all children. How can i propagate this orientation change from parent to its children with adding any additional interface.

Btw, this has nothing to with orientation change of the device. I want the orientation to change as per event encountered.

I can have multiple LinearLayout as its children and i don't want to set the orientation of all of these in a for loop since i am adding children programmatically

2 Answers
ll1 = (LinearLayout) findViewById(R.id.llayout);
ll2 = (LinearLayout) findViewById(R.id.llayout2);

Use setOrientation to change the orientation.

ll1.setOrientation(LinearLayout.VERTICAL);
ll2.setOrientation(LinearLayout.HORIZONTAL);
yourLinearLayout.setLayoutParams(new LayoutParams(LinearLayout.WRAP_CONTENT, LinearLayout.WRAP_CONTENT);
yourLinearLayout.setOrientation(LinearLayout.VERTICAL);

Do the same for the children

Related