Inflate layout programmatically within another layout

You could use something like

LayoutInflater inflater = LayoutInflater.from(context);

//to get the MainLayout
View view = inflater.inflate(container_destacado, null);
...
//Avoid pass null in the root it ignores spaces in the child layout

View inflatedLayout= inflater.inflate(R.layout.yourLayout, (ViewGroup) view, false);
containerDestacado.addView(inflatedLayout);

Leave a Comment