I met this issue too, and I just solved it now. I think my solution is easier:
-
create a inflater:
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
-
inflate the child layout:
View childLayout = inflater.inflate(R.layout.child, (ViewGroup) findViewById(R.id.child_id));
-
add it into parent:
parentLayout.addView(childLayout);
It’s done, enjoy it!