androidxmlandroid-layoutandroid-inflate

Inflate layout programmatically within another layout


I need help with my android app. I need inflate a layout within another layout and I dont know how I do. My xml code is this:


Solution

  • 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);