Inflate layout programmatically within another layout

前端 未结 8 2053
心在旅途
心在旅途 2020-11-30 04:54

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:

  • item.xml - I need inflate mult

8条回答
  •  攒了一身酷
    2020-11-30 05:01

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

提交回复
热议问题